Thread: little endian machines

  1. #16
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    As you say, round trips through a void pointer (for anything except a pointer to member) are a specific exception, identified in the standard. That still, however, doesn't allow you to dereference a pointer to char as if it was an int.

    Unfortunately, your search will be more difficult than finding a clause that says this is undefined behaviour, because this is one of those things that the standard leaves undefined, by omission, so you won't find a specific clause saying it is undefined.

    As per Section 1.3.12 "Undefined behavior" of ISO/IEC 14882 (aka the 1998 C++ standard)
    behavior, such as might arise upon use of an erroneous program construct or erroneous data, for which this International Standard imposes no requirements. Undefined behavior may also be expected when this International Standard omits the description of any explicit definition of behavior.
    I've added the bold for emphasis.

    If you do a hunt through, you will find all sorts of things (such as the clauses that result in a round-trip through a void pointer being valid) about what is allowed. It is the omissions that are important (and I assume the omissions occurred because it would have been very difficult to comprehensively articulate all possible cases of undefined behaviour).

    Incidentally, I can't claim credit (if credit it is) for this interpretation. Several mainstream compiler vendors, in reference to all C and C++ standard since 1989, have interpreted the standard that way. And I have yet to see anyone find a convincing interpretation of any clause in the standards that allows a rebuttal. Given that history, I might still be wrong in my interpretation, but I won't hold my breath in anticipation of being proven wrong.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  2. #17
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    The various methods of determining endianness at runtime may result in undefined or implementation-defined behavior, and yet these are the only methods available. The problem must be solved at any rate.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Little endian and Bit endian advantages and disadvantages
    By nkrao123@gmail. in forum C Programming
    Replies: 4
    Last Post: 09-11-2011, 04:40 AM
  2. Any significant Big Endian Machines?
    By abachler in forum Tech Board
    Replies: 9
    Last Post: 01-29-2009, 01:53 PM
  3. big endian-small endian problem
    By kapil1089thekin in forum C Programming
    Replies: 3
    Last Post: 05-15-2008, 06:47 PM
  4. Big Endian Little Endian Complex- Converting Characters
    By bd02eagle in forum C Programming
    Replies: 3
    Last Post: 07-11-2006, 01:01 AM
  5. Big endian/Little endian conversion
    By bonkey in forum Windows Programming
    Replies: 5
    Last Post: 09-25-2002, 02:29 PM

Tags for this Thread