Undefined behavior

This is a discussion on Undefined behavior within the C Programming forums, part of the General Programming Boards category; from C11 standards N1570 draft J.2 Undefined behavior An lvalue designating an object of automatic storage duration that could ...

  1. #1
    .
    Join Date
    Nov 2003
    Posts
    307

    Undefined behavior

    from C11 standards N1570 draft

    J.2 Undefined behavior

    An lvalue designating an object of automatic storage duration that could have been declared with the register storage class is used in a context that requires the value of the designated object, but the object is uninitialized. (6.3.2.1).
    I believe this is UB per the above: (it is obviously contrived)
    Code:
    int main()
    {
       int a;
       int b=a;
       printf("b=%d\n", b);
       return 0;
    }
    If that is not the correct reference in the C11 standard, then please show me the correct one. Thanks.

  2. #2
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    Well, "a" has automatic storage duration, it could have been declared with register, it is used in a context that requires its value (on the line you've highlighted), and it's uninitialised, so I'd say the quote accurately describes the cause of undefined behaviour in the snippet you've provided.

  3. #3
    .
    Join Date
    Nov 2003
    Posts
    307
    The standards text is a little bit impenetrable. I agree with you. Thanks. There are several standards people on the forums here so -- worth a question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Different behavior of gcc 3.x and 4.x
    By Sean M in forum C++ Programming
    Replies: 10
    Last Post: 08-10-2012, 03:49 PM
  2. Static vs. Dynamic Arrays, Getting Undefined Behavior
    By StefPrez in forum C++ Programming
    Replies: 11
    Last Post: 01-28-2012, 11:39 PM
  3. Is x=x++; Undefined Behavior?
    By envec83 in forum C Programming
    Replies: 5
    Last Post: 10-04-2011, 02:27 AM
  4. Undefined behavior from VC6 to 2k5
    By m37h0d in forum C++ Programming
    Replies: 10
    Last Post: 06-22-2011, 08:56 PM
  5. openGL: textures, gluLookAt, and undefined behavior
    By MK27 in forum Game Programming
    Replies: 7
    Last Post: 04-28-2009, 11:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21