Datatype symbol characters?

This is a discussion on Datatype symbol characters? within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm just wondering what the proper name is for those 1 letter symbols that tell the compiler the datatype ...

  1. #1
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545

    Datatype symbol characters?

    Hi,
    I'm just wondering what the proper name is for those 1 letter symbols that tell the compiler the datatype of a number?
    i.e.:
    Code:
    float num = 3.14f;
    I'm trying to find a list of all the symbols that I can use, but I'm not sure what they're called.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    numeric suffixes seems to be the correctest term I could find. Couldn't find a good link for all of them tho'. Here's a "syntax diagram" for numeric values:
    http://cpp.comsci.us/etymology/literals.html
    which gives you the ability to make your own table of what they are.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by cpjust View Post
    Hi,
    I'm just wondering what the proper name is for those 1 letter symbols that tell the compiler the datatype of a number?
    i.e.:
    Code:
    float num = 3.14f;
    I'm trying to find a list of all the symbols that I can use, but I'm not sure what they're called.
    The term "literal suffix" seems to have a higher proportion of relevant hits than any other term I tried.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,588
    The C++ Standard calls that a "type suffix".
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    OK thanks.
    I'm trying to find out if there's a type suffix for a short?

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by cpjust View Post
    OK thanks.
    I'm trying to find out if there's a type suffix for a short?
    Not that I'm aware of.

    Shorts are just like int, but can't be quite as big [for the pedants: assuming it's not a 16-bit machine where short and int are both 16 bits]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by matsp View Post
    Not that I'm aware of.

    Shorts are just like int, but can't be quite as big [for the pedants: assuming it's not a 16-bit machine where short and int are both 16 bits]

    --
    Mats
    Crap.

    The strange thing is, even if I use a cast, it still complains about:
    warning C4244: 'argument' : conversion from 'int' to 'unsigned short', possible loss of data
    on this line:
    Code:
    obj.SetUnsignedShort( obj.GetUnsignedShort() + static_cast<unsigned short>(1) );
    Why would adding 2 unsigned shorts get converted into an int?

    Obviously I can cast the whole thing like this:
    Code:
    obj.SetUnsignedShort( static_cast<unsigned short>(obj.GetUnsignedShort() + 1) );
    But I'm wondering why I need to?

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by cpjust View Post
    Crap.

    The strange thing is, even if I use a cast, it still complains about:

    on this line:
    Code:
    obj.SetUnsignedShort( obj.GetUnsignedShort() + static_cast<unsigned short>(1) );
    Why would adding 2 unsigned shorts get converted into an int?

    Obviously I can cast the whole thing like this:
    Code:
    obj.SetUnsignedShort( static_cast<unsigned short>(obj.GetUnsignedShort() + 1) );
    But I'm wondering why I need to?
    Strange, but I guess that the return value from GetUnsignedShort() is promoted to int - where you put the cast should make no big difference [at least not unless you have very weird hardware that does math differently than "standard"].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    All calculations are done at at least int width. No matter what kinds of integers you add together, they'll end up an int or bigger.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 04:44 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 04:27 AM

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