typedef modifiers

This is a discussion on typedef modifiers within the C Programming forums, part of the General Programming Boards category; Simple question really, why is the following not legitimate syntax? Code: typedef long long foo_t; foo_t f; unsigned foo_t uf; ...

  1. #1
    Registered User SKeane's Avatar
    Join Date
    Sep 2006
    Location
    England
    Posts
    234

    typedef modifiers

    Simple question really, why is the following not legitimate syntax?

    Code:
    typedef long long foo_t;
    
    foo_t f;
    unsigned foo_t uf;
    And yes, I do realise I can do ...

    Code:
    typedef long long foo_t;
    typedef unsigned long long ufoo_t;
    
    foo_t f;
    ufoo_t uf;
    I was just curious why the first syntax isn't allowed.
    Last edited by SKeane; 09-26-2006 at 03:36 AM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    5,852
    Because the typedef creates foo_t as a synonym for a type named "long long", which is more precisely described as "long long signed". A basic rule is that no declaration can have more than one of the set {long, short} or of the set {signed, unsigned} as type modifiers (eg it is not possible to declare something of type "long short" or "short short").

    "long long" is actually an allowed exception to that rule introduced by more recent standards ("long long" is treated as a single type modifier rather than a pair) but that is essentially how it works --- declaring something as a "unsigned signed long long int" doesn't make sense.

    In terms of the language grammar, the "typedef" keyword is treated as another storage modifier, and the original rule was that it is not possible to add other storage modifiers when using a typedef'd type. However, there are a few exceptions now built into the grammar to accomodate the "long long" type, so my description above is functionally correct, if not necessarily how a compiler does it.
    Last edited by grumpy; 09-26-2006 at 05:24 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  3. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  4. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 08:22 AM
  5. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 06:35 AM

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