sizeof operator

This is a discussion on sizeof operator within the C Programming forums, part of the General Programming Boards category; Hello given the code Code: struct COORD {float x,y,z}; are both Code: sizeof (struct COORD) and Code: sizeof (COORD} both ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    70

    sizeof operator

    Hello
    given the code
    Code:
    struct COORD {float x,y,z};
    are both
    Code:
    sizeof (struct COORD)
    and
    Code:
    sizeof (COORD}
    both valid?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Only the first is valid after fixing the structure declaration. C requires the struct keyword (unlike C++) except when the struct has been typedef'd. If you did this:
    Code:
    typedef struct COORD {float x,y,z;} COORD;
    Then they would both be valid in C. Note that the structure tag and the typedef identifier are both in different name spaces, and thus the same name can be used. But it can be confusing to some readers.
    My best code is written with the delete key.

  3. #3
    Registered User kinghajj's Avatar
    Join Date
    Jun 2003
    Posts
    218
    I never did like the necessity of using 'struct' to declare them, but as prelude says, just use typedef and you'll be fine
    Last edited by kinghajj; 05-19-2004 at 09:53 PM. Reason: mis-spelling
    01011001 01101111 01110101 00100000 01110100 01101111 01101111 1101011 00100000 01110100 01101000 01101001 01110011 00100000 01101101 01110101 01100011 01101000 00100000 01110100 01101000 01101101 01100101 00100000 01110100 01101111 00100000 01110010 01100101 01100001 01100100 00100000 01011001 01101000 01101001 01110011 00111111 00100000 01000100 01100001 01101101 01101110 00100001 00000000

  4. #4
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    I assume you meant struct, I always like the struct keyword, kind of made the language unique, unlike the c++ style where structs are like, well, typedef'ed variables
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  5. #5
    Registered User
    Join Date
    May 2004
    Posts
    70
    pardon my ignorance but what is a name space?

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >pardon my ignorance but what is a name space?
    Code:
    6.2.3 Name spaces of identifiers
    
    1 If more than one declaration of a particular identifier is visible at any point in a
    translation unit, the syntactic context disambiguates uses that refer to different entities.
    Thus, there are separate name spaces for various categories of identifiers, as follows:
    
     label names (disambiguated by the syntax of the label declaration and use);
     the tags of structures, unions, and enumerations (disambiguated by following any24)
    of the keywords struct, union, or enum);
     the members of structures or unions; each structure or union has a separate name
    space for its members (disambiguated by the type of the expression used to access the
    member via the . or -> operator);
     all other identifiers, called ordinary identifiers (declared in ordinary declarators or as
    enumeration constants).
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 08:05 AM
  2. Replies: 6
    Last Post: 10-15-2007, 09:05 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Replies: 14
    Last Post: 06-28-2006, 02:58 AM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-07-2003, 12:51 AM

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