tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] __LINE__ and #line undelying type


From: Elijah Stone
Subject: Re: [Tinycc-devel] __LINE__ and #line undelying type
Date: Thu, 15 Apr 2021 21:42:12 -0700 (PDT)

On Fri, 16 Apr 2021, Christian Jullien wrote:

C standard says:
_ _LINE_ _ The presumed line number (within the current source file) of the 
current
source line (an integer constant).

So, it should be a signed integer (same as int on your running architecture 
which is internally either int32_t or int64_t depending on how int is 
represented).
For type safety, it is important that __LINE__ is an int because a lot of code 
uses this type to call functions as below:

void debug(const char* file, int line, const char* msg) {
 printf("%s(%d) %s\n", file, line msg);
}

gcc, clang and tcc all use an int as you can see below, so tcc looks right to 
me:

You are not testing the right thing. It is an int literal in any case, but tcc allows it to overflow.
Here is a better test:

$ cat tt.c
#line 2147483644
#include <stdio.h>
#define STR2(x) #x
#define STR(x) STR2(x)
int main(void) {
        puts(STR(__LINE__));
}
$ gcc -o tt tt.c && ./tt
2147483648
$ tcc -o tt tt.c && ./tt
-2147483648

 -E



reply via email to

[Prev in Thread] Current Thread [Next in Thread]