Thread: Datatype symbol characters?

  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
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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
    28,413
    The C++ Standard calls that a "type suffix".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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,895
    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, 03: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, 02:28 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM