0

In the list of constants:

  • '\0' char
  • true, false boolean
  • 2U unsigned / unsigned int
  • 2 int
  • 2L long
  • 2.0 double
  • 2.0f float
  • "" string
  • 0x0 hexadecimal integer
  • 02 octal integer
  • 1E-8 exponential

I see primarily all the constants corresponding to their standard data type or interpretation value. However I don't see a specific for (short / short integer / 2 bytes / word / int16). Is there any particular, reasonable argument for its absence ?

Imobilis
  • 1,475
  • 8
  • 29
  • There's really no point for short constants in C; int is at least the same size as short. This probably should have been closed as being primarily opinion based, though. – Bobby Sacamano Nov 13 '15 at 02:44
  • Constant literals are being located in read-only memory in private sector of RAM, it still burdens memory. So there is a huge difference between short and int. – Imobilis Nov 13 '15 at 02:46
  • Side-note: In C (not C++, it's one of the discrepancies between the two), the ["`char` literal" (`'\0'`) is actually of type `int`](http://en.cppreference.com/w/c/language/character_constant). In C++, the number of characters changes the type; [it's `char` with a single character, or `int` (like C) with more than one](http://en.cppreference.com/w/cpp/language/character_literal). – ShadowRanger Nov 13 '15 at 02:47
  • That's what I call with no point ^ This wouldn't ruin the portability, memory though. So I truly see no point in it. Treating a char literal as int ... uh. Interpreting int with char.. uh. Sounds very unfit. – Imobilis Nov 13 '15 at 02:49
  • @Malina are you saying that constant literals like 2 and '\0' are stored in memory? Why would that be necessary? – Bobby Sacamano Nov 13 '15 at 02:51
  • @BobbySacamano Of course they are stored. It is still data. Where are stored varies from one compiler to another so I cannot tell implicitly. Besides, HDD storage still counts lol. – Imobilis Nov 13 '15 at 02:53
  • @Malina When I look at the assembly output of something like `int a = '\0'`, it evaluates to `mov [a], 2`. Is it defined somewhere in the standard that every literal has to exist in memory? – Bobby Sacamano Nov 13 '15 at 02:57
  • AFAIRC It says that they are treated just like regular variables except that their values occur only once and cannot be modified respectively. I know that the data must be created first in order to exist in memory and contain information (for instance values from constants), otherwise a plain constant wouldn't make much sense. So here is more a matter of explicit conversion. In modern compilers.. even in ancient compilers it does that instead.. to maintain memory. – Imobilis Nov 13 '15 at 03:01

0 Answers0