When you define a value in C, how does the compiler select a data type

Just a general programming question: when you define a value in C (or any language, I suppose), how does the compiler know how to handle the value? For instance:

#define CountCycle  100000

I would suggest that it CountCycleis a data type with long integers, but this is just an assumption. I suppose it could also be floata double(and not int, since it does not exceed ~ 32k), etc.

How does the compiler select the data type for the value #define? I do not have an application to answer this question; I'm just curious.

+4
source share
4 answers

. 100000 CountCycle.

, . 100000 int, , a long, .

. ++ Reference C Reference.

+12

CountCycle . 100000 , .

100000, .

, ( C, 6.4.4.1 )

5 , .

int
long int
long long int

, long int, .

#define CountCycle  100000l

long int, . long long int.

, .

#define CountCycle  100000.0
0

, C :

" " - .

"# define" - , . #define. #define , - , - , .

-

#define BUFFER_SIZE 1000

BUFFER_SIZE 1000 .

-1

. 100000 CountCycle.

, , . , , , , , float . , . ? , , , .

, - , : ; ; - . erros - , - :

#define MY_FLOAT_DATA   (float)4.55
#define MY_INTEGER_DATA (int)4
Run codeHide result
-1
source

Source: https://habr.com/ru/post/1684827/


All Articles