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: Vincent Lefevre
Subject: Re: [Tinycc-devel] __LINE__ and #line undelying type
Date: Fri, 16 Apr 2021 11:51:30 +0200
User-agent: Mutt/2.0.6+148 (869c6cc4) vl-132933 (2021-04-10)

On 2021-04-16 07:11:27 +0200, Christian Jullien wrote:
> C standard says nothing about line int overflow so tcc can't be
> declared as wrong.

I've looked at the C standard, and I could see nowhere that an
implementation is allowed to restrict the line number to the int
type. Actually, it more or less implies the opposite, at least
in C99 (I don't know in previous versions):

    6.10.4 Line control
[...]
 3  A preprocessing directive of the form

      # line digit-sequence new-line

    causes the implementation to behave as if the following sequence
    of source lines begins with a source line that has a line number
    as specified by the digit sequence (interpreted as a decimal
    integer). The digit sequence shall not specify zero, nor a number
    greater than 2147483647.

So I suppose this means that values up to 2147483647 (and probably
the following ones, otherwise using 2147483647 would be useless)
need to be supported. In implementations with 16-bit int, this would
mean that the line number for such large values is represented by a
long (or long long).

Also note that __LINE__ expand to an integer constant, which doesn't
include negative integers.

> Now I agree with you that tcc should better handle those cases (as
> gcc does?)

It should just follow the C standard. In practice, it should at least
support values up to 2^32 - 1 (2147483647 is 2^31 - 1, so that
supporting 32-bit line numbers as positive integers is needed, and
it is highly unlikely that huge source files reach 33-bit values).
But of course, if you use a 64-bit type for the internal type, this
is fine.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



reply via email to

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