Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #77204

Re: Aliasing through a union pointer

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: Aliasing through a union pointer
Date 2015-11-26 20:51 +1300
Message-ID <dbns0dFea62U4@mid.individual.net> (permalink)
References (14 earlier) <286a81d0-5dfc-4ce5-ae56-060a7818c167@googlegroups.com> <dbn08lFea62U1@mid.individual.net> <9baa8a17-e9a1-4850-9445-c576afbbf792@googlegroups.com> <dbn4kiFea62U2@mid.individual.net> <db024f05-26ba-4c87-b78a-6821d2dd3d93@googlegroups.com>

Show all headers | View raw


supercat@casperkitty.com wrote:
> On Wednesday, November 25, 2015 at 7:13:05 PM UTC-6, Ian Collins wrote:
>> But that would preclude calling any (library) function that didn't have
>> the qualification.  That's why I said supporting misaligned access
>> impacts the entire program.
>
> And I'd say that library functions would be limited to using normal pointers;
> I'm curious for which library problems you think that would be a problem.
> if one wants to read a number from the a file into a bitfield, one can't use
> fscanf to load data into the bit-field directly--one must read it into a
> temporary variable and then copy that manually.  How many library routines
> are there that accept a non-character pointer type and write a lot of data
> to it?

You don't have to.  A single read or write is all that is required.  If 
I understand your concept correctly and you have a new qualifier, you 
will need to copy data between qualified and unqualified pointers, which 
is little different from copying data to and from packed external 
message formats.

>> Because misaligned pointers can leak.
>
> Only if the type system allows them to be given to code that expects normal
> pointers.

See above.

>> That depends on how much of the "new" stuff in C99 you use :)
>
> The languages also have different rules about things like aliasing and
> various other oddities.

None of which make any practical difference in normal code.  I mix C and 
C++ often and I must admit I would have to go looking for any such 
differences.

>>> Was it slower because the code was trying to do unaligned reads which then
>>> generated traps, or because the code was using sequences of byte reads and
>>> putting them together?
>>
>> The former.
>
> Well don't do that. >:*3  If one tells the compiler to *expect* unaligned
> data (possible in at least some compilers, and IMHO should be defined in the
> Standard even if compilers were allowed to refuse compilation of programs
> specifying it) the performance impact would be greatly reduced to be no
> worse than (and in many cases not as bad as) the cost of user code building
> up larger types from smaller ones.

Compilers for machines such as SPARC would have to refuse due to 
hardware restrictions.  So you don't gain any portability benefits over 
compiler extensions.

-- 
Ian Collins

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Aliasing through a union pointer Ian Pilcher <arequipeno@gmail.com> - 2015-11-23 10:14 -0600
  Re: Aliasing through a union pointer Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-23 11:43 -0500
    Re: Aliasing through a union pointer Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-23 11:49 -0500
    Re: Aliasing through a union pointer Ian Pilcher <arequipeno@gmail.com> - 2015-11-23 13:22 -0600
      Re: Aliasing through a union pointer Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-23 14:38 -0500
        Re: Aliasing through a union pointer Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-25 10:38 -0800
          Re: Aliasing through a union pointer Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-25 14:17 -0500
            Re: Aliasing through a union pointer Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-27 13:16 -0800
      Re: Aliasing through a union pointer David Brown <david.brown@hesbynett.no> - 2015-11-23 21:46 +0100
        Re: Aliasing through a union pointer Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-23 22:20 +0000
          Re: Aliasing through a union pointer Stephen Sprunk <stephen@sprunk.org> - 2015-11-23 16:52 -0600
            Re: Aliasing through a union pointer Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-23 23:10 +0000
              Re: Aliasing through a union pointer Stephen Sprunk <stephen@sprunk.org> - 2015-11-23 19:05 -0600
          Re: Aliasing through a union pointer Nick Bowler <nbowler@draconx.ca> - 2015-11-23 22:51 +0000
          Re: Aliasing through a union pointer Keith Thompson <kst-u@mib.org> - 2015-11-23 15:49 -0800
            Re: Aliasing through a union pointer supercat@casperkitty.com - 2015-11-23 16:01 -0800
          Re: Aliasing through a union pointer David Brown <david.brown@hesbynett.no> - 2015-11-24 09:55 +0100
            Re: Aliasing through a union pointer Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-24 14:29 +0000
              Re: Aliasing through a union pointer David Brown <david.brown@hesbynett.no> - 2015-11-24 22:58 +0100
                Re: Aliasing through a union pointer Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-11-24 17:30 -0500
                Re: Aliasing through a union pointer supercat@casperkitty.com - 2015-11-24 15:27 -0800
                Re: Aliasing through a union pointer Ian Collins <ian-news@hotmail.com> - 2015-11-25 12:57 +1300
                Re: Aliasing through a union pointer supercat@casperkitty.com - 2015-11-24 16:31 -0800
                Re: Aliasing through a union pointer Ian Collins <ian-news@hotmail.com> - 2015-11-25 18:28 +1300
                Re: Aliasing through a union pointer supercat@casperkitty.com - 2015-11-25 06:54 -0800
                Re: Aliasing through a union pointer Ian Collins <ian-news@hotmail.com> - 2015-11-26 08:59 +1300
                Re: Aliasing through a union pointer supercat@casperkitty.com - 2015-11-25 13:01 -0800
                Re: Aliasing through a union pointer Ian Collins <ian-news@hotmail.com> - 2015-11-26 12:58 +1300
                Re: Aliasing through a union pointer supercat@casperkitty.com - 2015-11-25 16:44 -0800
                Re: Aliasing through a union pointer Ian Collins <ian-news@hotmail.com> - 2015-11-26 14:12 +1300
                Re: Aliasing through a union pointer supercat@casperkitty.com - 2015-11-25 21:34 -0800
                Re: Aliasing through a union pointer Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-25 21:55 -0800
                Re: Aliasing through a union pointer Ian Collins <ian-news@hotmail.com> - 2015-11-26 20:51 +1300
                Re: Aliasing through a union pointer supercat@casperkitty.com - 2015-11-26 11:39 -0800
                Re: Aliasing through a union pointer Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-26 00:06 +0000
            Re: Aliasing through a union pointer Keith Thompson <kst-u@mib.org> - 2015-11-24 11:51 -0800
              Re: Aliasing through a union pointer supercat@casperkitty.com - 2015-11-24 12:20 -0800
                Re: Aliasing through a union pointer Keith Thompson <kst-u@mib.org> - 2015-11-24 21:52 -0800
                Re: Aliasing through a union pointer supercat@casperkitty.com - 2015-11-25 08:30 -0800
              Re: Aliasing through a union pointer David Brown <david.brown@hesbynett.no> - 2015-11-24 23:04 +0100
  Re: Aliasing through a union pointer Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-25 10:10 -0800
    Re: Aliasing through a union pointer Richard Damon <Richard@Damon-Family.org> - 2015-11-25 11:02 -0800
      Re: Aliasing through a union pointer Philip Lantz <prl@canterey.us> - 2015-11-26 13:06 -0800
        Re: Aliasing through a union pointer Richard Damon <Richard@Damon-Family.org> - 2015-11-26 13:09 -0800
      Re: Aliasing through a union pointer Tim Rentsch <txr@alumni.caltech.edu> - 2015-11-27 13:08 -0800

csiph-web