Thread: Does a struct pointer always point to the struct's 1st member?

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    6

    Does a struct pointer always point to the struct's 1st member?

    Just a simple question.

    Is it guaranteed that the pointer to a structure always points to the structure's first member?

    e.g.

    Code:
    struct {
        data_type a;
        data_type b;
        ...
    } my_struct;
    Is it always true that &my_struct == &(my_struct.a) ?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Yes it does.

    The value may be correct, but the type will always be wrong.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Replies: 6
    Last Post: 05-15-2009, 08:38 AM
  3. For the numerical recipes in C types!
    By Smattacus in forum C Programming
    Replies: 5
    Last Post: 10-28-2008, 07:57 PM
  4. A struct member as a pointer to a variable
    By mc61 in forum C Programming
    Replies: 5
    Last Post: 01-27-2008, 08:40 AM
  5. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM