8

I'm trying to figure out what's the real meaning behind these suffixes. In other words I'm trying to "translate" them.

+----+--------------+--------+
|    |     Type     | Suffix |
+----+--------------+--------+
|  1 | byte         | uy     |
|  2 | sbyte        | y      |
|  3 | int16        | s      |
|  4 | uint16       | us     |
|  5 | int, int32   |        |
|  6 | uint, uint32 | u      |
|  7 | int64        | L      |
|  8 | uint64       | UL     |
|  9 | float        |        |
| 10 | float32      | f      | (edited, thanks Thomas)
| 11 | decimal      | M      |
+----+--------------+--------+

E.g. I assume that "f" stands for f loat. But for what does e.g. "M" stand for. Why isn't "d" used for d ecimal ? For what does "uy" stand for? And so forth ...

Can anyone "translate" this ?

Abel
  • 56,041
  • 24
  • 146
  • 247
Miro
  • 1,778
  • 6
  • 24
  • 42
  • 1
    s for short, l for long. us and ul for unsigned short and unsigned long. D might be confusing for decimal because in c, d is an int. I am just speculating on that one. b is used for ascii characters and B for strings, so y is probably just the next best choice.. also speculation – Gray Feb 07 '13 at 19:46
  • 3
    FYI: [The complete list of literal suffixes on MSDN](http://msdn.microsoft.com/en-us/library/dd233193.aspx). – Daniel Feb 07 '13 at 19:57
  • 1
    Since on that list `sbyte` is `y` it makes sense that `byte` would be `uy` since it's an Unsigned bYte. – Joel Mueller Feb 07 '13 at 22:58
  • Note that there is at least some crossover with [other languages](http://stackoverflow.com/questions/166752/c-sharp-compiler-number-literals). – Benjol Feb 08 '13 at 06:02

2 Answers2

9

I can only speculate, but note that since a-f are valid hexadecimal values, they can't be used for suffixes for integral types. That's probably the reason that bYte and deciMal get the slightly less mnemonic abbreviations. Likewise, note that there are separate (very rarely used) suffices for using hexadecimal notation with floats: LF for floats and lf for float32s.

By these rules, all of the following are valid literals:

0xb  // int, in hex
0xby // byte, in hex
0xabcdef // int, in hex
0xabcdeflf // float32, in hex
kvb
  • 54,864
  • 2
  • 91
  • 133
9

I think @kvb made a really good speculation. Here are two minor additions:

  • There is one minor issue in your table, f is a suffix used for float32 (also called single corresponding to System.Single) while floating point without suffix becomes F# float (corresponding to System.Double). The naming of floats is really confused in F#, so I don't think this has any special logic (just a need to distinguish between two kinds of floats).

  • Your table also does not include l (which is used for int). This means that int16, int32 and int64 have suffixes s, l and L respectively (which probably means, "short", "long" and "long long" in the C terminology).

  • I like to read the M suffix in decimals as "money", because decimal is most often used to represent money (because of its high precision). I'm not sure if this is the reason why the prefix is M, but it is easy to remember :-).

Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
  • `Decimal` actually maps pretty closely to the SQL Server `money` datatype, so you're probably right about `M`. – brianary Nov 05 '21 at 15:58