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

This is a discussion on Does a struct pointer always point to the struct's 1st member? within the C Programming forums, part of the General Programming Boards category; Just a simple question. Is it guaranteed that the pointer to a structure always points to the structure's first 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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 07:40 AM
  5. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM

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