Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The only perfect science is hind-sight.


devel / comp.lang.c / Re: Preprocessor <-> compiler

SubjectAuthor
* Preprocessor <-> compilerThiago Adams
+- Re: Preprocessor <-> compilerThiago Adams
+* Re: Preprocessor <-> compilerBart
|`* Re: Preprocessor <-> compilerThiago Adams
| `* Re: Preprocessor <-> compilerBart
|  `* Re: Preprocessor <-> compilerThiago Adams
|   `* Re: Preprocessor <-> compilerBart
|    `- Re: Preprocessor <-> compilerKeith Thompson
`* Re: Preprocessor <-> compilerAndrey Tarasevich
 `- Re: Preprocessor <-> compilerThiago Adams

1
Preprocessor <-> compiler

<68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18528&group=comp.lang.c#18528

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1214:: with SMTP id y20mr8744029qtx.152.1633268871289;
Sun, 03 Oct 2021 06:47:51 -0700 (PDT)
X-Received: by 2002:ac8:4e30:: with SMTP id d16mr8537057qtw.309.1633268871051;
Sun, 03 Oct 2021 06:47:51 -0700 (PDT)
Path: rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 3 Oct 2021 06:47:50 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=189.6.249.78; posting-account=xFcAQAoAAAAoWlfpQ6Hz2n-MU9fthxbY
NNTP-Posting-Host: 189.6.249.78
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com>
Subject: Preprocessor <-> compiler
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Sun, 03 Oct 2021 13:47:51 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 61
 by: Thiago Adams - Sun, 3 Oct 2021 13:47 UTC

I have implemented the preprocessor 'on demand' in my c compiler
front end and I was kind of regretting it because the code become
much more complex compared with preprocess in everything in
advance and separately.

I was planning to change it to simplify the code but I realized that
this makes it possible the integration with the compiler.

My parser asks 'give me the next token’ for a preprocessor state machine
and it returns only tokens already preprocessed.

For instance:

void F() {
char ch =
#if 0
'a'
#else
'b'
#endif
;
} after '=' the parser pulls the next token and the preprocessor move
its internal state consuming preprocessor tokens until it finds 'b' returning it’.

It asks again and the preprocessor returns ';' changing it internal state
after consuming (but not returning) #endif.

The internal state (#include, #ifdefs, #endif) are kept in stacks.
Macro expansion is on demand as well.

This preprocessor state machine has an advantage.

It still happens before the compiler phase but it has the compiler
context and could access it.

That means that #if could ask anything for the compiler like sizeof
of the variable on scope, or if a variable/function exists etc.

Considering this.. I was wondering if the C language could change its
concepts to allow this in the future.

When we read code, we don't do the preprocessor "separated" in
your mind we do it "on demand" as well.

The invention of _Static_assert for instance would not be necessary

Instead of

_Static_assert( sizeof(x) == sizeof(int), "must be sizeof int");

we could just write:

#if sizeof(x) != sizeof(int)
#error x must be == sizeof int
#endif

Re: Preprocessor <-> compiler

<e8624232-f30d-4db8-8b06-1ff769aee582n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18529&group=comp.lang.c#18529

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:a54c:: with SMTP id o73mr6325923qke.334.1633275482191;
Sun, 03 Oct 2021 08:38:02 -0700 (PDT)
X-Received: by 2002:ac8:5752:: with SMTP id 18mr9384442qtx.203.1633275481914;
Sun, 03 Oct 2021 08:38:01 -0700 (PDT)
Path: rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 3 Oct 2021 08:38:01 -0700 (PDT)
In-Reply-To: <68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=189.6.249.78; posting-account=xFcAQAoAAAAoWlfpQ6Hz2n-MU9fthxbY
NNTP-Posting-Host: 189.6.249.78
References: <68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e8624232-f30d-4db8-8b06-1ff769aee582n@googlegroups.com>
Subject: Re: Preprocessor <-> compiler
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Sun, 03 Oct 2021 15:38:02 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 49
 by: Thiago Adams - Sun, 3 Oct 2021 15:38 UTC

On Sunday, October 3, 2021 at 10:47:58 AM UTC-3, Thiago Adams wrote:

> My parser asks 'give me the next token’ for a preprocessor state machine
> and it returns only tokens already preprocessed.

Something assumed to be true is that the compiler state does not change
while preprocessor is consuming pptokens. I guess this is true until
we find the next parser phase token.

The problem is when we need two tokens ahead because the parser
state could change after finding the first compiler phase token.

(the compiler depends on the preprocessor and vice versa)

{
​if (1) {
​​int a; /*here*/
​}
​ #if sizeof(a)
​#endif
}

If after ​​int a; /*here*/ the compiler asks two tokens
then the preprocessor will have the compiler state when it started
but it will have to consume more pptokens until it finds the
second '}'.

In this case the compiler state is outdated because the variable 'a'
is out of the scope but the preprocessor does not know because the
compiler did not consume the first token to change its state.

In this case the preprocessor will evaluated the condition as if a
where in the scope.

I am not sure how big is this problem. I think it cannot be well defined
because the way compiler will need/consume look ahead tokens cannot be
specified. Some compiler may use look ahead and others not and the evaluation
could give different results in each compiler.

Re: Preprocessor <-> compiler

<sjclfk$e3c$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18530&group=comp.lang.c#18530

  copy link   Newsgroups: comp.lang.c
Path: rocksolid2!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Preprocessor <-> compiler
Date: Sun, 3 Oct 2021 17:24:18 +0100
Organization: A noiseless patient Spider
Lines: 76
Message-ID: <sjclfk$e3c$1@dont-email.me>
References: <68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 3 Oct 2021 16:24:20 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="61dedff8bdc4cd6e2c4ae53830bb2ffd";
logging-data="14444"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7ygtVQUsZHIBtYFotJJkKif46jMymrW0="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:14Xqlxf//EAGW5rvzyCCy2Ft3l0=
In-Reply-To: <68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211003-6, 3/10/2021), Outbound message
 by: Bart - Sun, 3 Oct 2021 16:24 UTC

On 03/10/2021 14:47, Thiago Adams wrote:
> I have implemented the preprocessor 'on demand' in my c compiler
> front end and I was kind of regretting it because the code become
> much more complex compared with preprocess in everything in
> advance and separately.
>
> I was planning to change it to simplify the code but I realized that
> this makes it possible the integration with the compiler.
>
> My parser asks 'give me the next token’ for a preprocessor state machine
> and it returns only tokens already preprocessed.
>
> For instance:
>
> void F() {
> char ch =
> #if 0
> 'a'
> #else
> 'b'
> #endif
> ;
> }
> after '=' the parser pulls the next token and the preprocessor move
> its internal state consuming preprocessor tokens until it finds 'b' returning it’.
>
> It asks again and the preprocessor returns ';' changing it internal state
> after consuming (but not returning) #endif.
>
> The internal state (#include, #ifdefs, #endif) are kept in stacks.
> Macro expansion is on demand as well.
>
> This preprocessor state machine has an advantage.
>
> It still happens before the compiler phase but it has the compiler
> context and could access it.
>
> That means that #if could ask anything for the compiler like sizeof
> of the variable on scope, or if a variable/function exists etc.
>
> Considering this.. I was wondering if the C language could change its
> concepts to allow this in the future.
>
> When we read code, we don't do the preprocessor "separated" in
> your mind we do it "on demand" as well.
>
> The invention of _Static_assert for instance would not be necessary
>
> Instead of
>
> _Static_assert( sizeof(x) == sizeof(int), "must be sizeof int");
>
> we could just write:
>
> #if sizeof(x) != sizeof(int)

This requires that the lexer knows about symbol tables, scopes and user
types, and that operations such as building those types and user types
and the name resolution required to figure out which x is intended, are
all done while parsing.

In other words, that part needs to be single pass, which puts a
constraint on the compiler.

Also, what happens when someone /only/ wants to do a preprocessing pass?
Then 'sizeof(x)' is meaningless.

Would you have to remove that ability from the language? I think more
than a few compilers depend on a third party preprocessors, and various
language processing tools may depend on it too.

So it's an unlikely retrofit for C.

For a new language though, or one which eventually transpiles to C, you
can define it as you like.

Re: Preprocessor <-> compiler

<0e8f856f-696b-4f32-9b05-f44e04c2ffffn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18532&group=comp.lang.c#18532

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:4e8f:: with SMTP id 15mr9477736qtp.189.1633283711409;
Sun, 03 Oct 2021 10:55:11 -0700 (PDT)
X-Received: by 2002:a05:622a:1652:: with SMTP id y18mr9632148qtj.226.1633283711140;
Sun, 03 Oct 2021 10:55:11 -0700 (PDT)
Path: rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 3 Oct 2021 10:55:10 -0700 (PDT)
In-Reply-To: <sjclfk$e3c$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=189.6.249.78; posting-account=xFcAQAoAAAAoWlfpQ6Hz2n-MU9fthxbY
NNTP-Posting-Host: 189.6.249.78
References: <68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com> <sjclfk$e3c$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <0e8f856f-696b-4f32-9b05-f44e04c2ffffn@googlegroups.com>
Subject: Re: Preprocessor <-> compiler
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Sun, 03 Oct 2021 17:55:11 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 103
 by: Thiago Adams - Sun, 3 Oct 2021 17:55 UTC

On Sunday, October 3, 2021 at 1:24:32 PM UTC-3, Bart wrote:
> On 03/10/2021 14:47, Thiago Adams wrote:
> > I have implemented the preprocessor 'on demand' in my c compiler
> > front end and I was kind of regretting it because the code become
> > much more complex compared with preprocess in everything in
> > advance and separately.
> >
> > I was planning to change it to simplify the code but I realized that
> > this makes it possible the integration with the compiler.
> >
> > My parser asks 'give me the next token’ for a preprocessor state machine
> > and it returns only tokens already preprocessed.
> >
> > For instance:
> >
> > void F() {
> > char ch =
> > #if 0
> > 'a'
> > #else
> > 'b'
> > #endif
> > ;
> > }
> > after '=' the parser pulls the next token and the preprocessor move
> > its internal state consuming preprocessor tokens until it finds 'b' returning it’.
> >
> > It asks again and the preprocessor returns ';' changing it internal state
> > after consuming (but not returning) #endif.
> >
> > The internal state (#include, #ifdefs, #endif) are kept in stacks.
> > Macro expansion is on demand as well.
> >
> > This preprocessor state machine has an advantage.
> >
> > It still happens before the compiler phase but it has the compiler
> > context and could access it.
> >
> > That means that #if could ask anything for the compiler like sizeof
> > of the variable on scope, or if a variable/function exists etc.
> >
> > Considering this.. I was wondering if the C language could change its
> > concepts to allow this in the future.
> >
> > When we read code, we don't do the preprocessor "separated" in
> > your mind we do it "on demand" as well.
> >
> > The invention of _Static_assert for instance would not be necessary
> >
> > Instead of
> >
> > _Static_assert( sizeof(x) == sizeof(int), "must be sizeof int");
> >
> > we could just write:
> >
> > #if sizeof(x) != sizeof(int)
> This requires that the lexer knows about symbol tables, scopes and user
> types, and that operations such as building those types and user types
> and the name resolution required to figure out which x is intended, are
> all done while parsing.

The lexer ask questions direct to the compiler and the compiler has
all the tables.

compiler says : "give me the next token, in case you need ask me".


> In other words, that part needs to be single pass, which puts a
> constraint on the compiler.

Yes, good point.
> Also, what happens when someone /only/ wants to do a preprocessing pass?
> Then 'sizeof(x)' is meaningless.

Would be an error.

> Would you have to remove that ability from the language? I think more
> than a few compilers depend on a third party preprocessors, and various
> language processing tools may depend on it too.
>
> So it's an unlikely retrofit for C.

I think all the preprocessor is already very mixed with the compiler
I have several samples.

-C++ added digit separators and they had to change pp-number (preprocessor
definition of number). You cannot use an external preprocessor that is
not synchronized.
-#pragma are used to control the compiler. what happen using an external preprocessor
will just remove the content?

__func__ is already funny.

Re: Preprocessor <-> compiler

<sjctg9$bim$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18533&group=comp.lang.c#18533

  copy link   Newsgroups: comp.lang.c
Path: rocksolid2!news.neodome.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Preprocessor <-> compiler
Date: Sun, 3 Oct 2021 19:41:10 +0100
Organization: A noiseless patient Spider
Lines: 116
Message-ID: <sjctg9$bim$1@dont-email.me>
References: <68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com>
<sjclfk$e3c$1@dont-email.me>
<0e8f856f-696b-4f32-9b05-f44e04c2ffffn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 3 Oct 2021 18:41:13 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="61dedff8bdc4cd6e2c4ae53830bb2ffd";
logging-data="11862"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HzuWFCpmd5xgPX7BRBjDNQAREHgN9CyM="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:KZwqM4any3KQZ8qCfbpxgsYVms8=
In-Reply-To: <0e8f856f-696b-4f32-9b05-f44e04c2ffffn@googlegroups.com>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211003-10, 3/10/2021), Outbound message
 by: Bart - Sun, 3 Oct 2021 18:41 UTC

On 03/10/2021 18:55, Thiago Adams wrote:
> On Sunday, October 3, 2021 at 1:24:32 PM UTC-3, Bart wrote:
>> On 03/10/2021 14:47, Thiago Adams wrote:
>>> I have implemented the preprocessor 'on demand' in my c compiler
>>> front end and I was kind of regretting it because the code become
>>> much more complex compared with preprocess in everything in
>>> advance and separately.
>>>
>>> I was planning to change it to simplify the code but I realized that
>>> this makes it possible the integration with the compiler.
>>>
>>> My parser asks 'give me the next token’ for a preprocessor state machine
>>> and it returns only tokens already preprocessed.
>>>
>>> For instance:
>>>
>>> void F() {
>>> char ch =
>>> #if 0
>>> 'a'
>>> #else
>>> 'b'
>>> #endif
>>> ;
>>> }
>>> after '=' the parser pulls the next token and the preprocessor move
>>> its internal state consuming preprocessor tokens until it finds 'b' returning it’.
>>>
>>> It asks again and the preprocessor returns ';' changing it internal state
>>> after consuming (but not returning) #endif.
>>>
>>> The internal state (#include, #ifdefs, #endif) are kept in stacks.
>>> Macro expansion is on demand as well.
>>>
>>> This preprocessor state machine has an advantage.
>>>
>>> It still happens before the compiler phase but it has the compiler
>>> context and could access it.
>>>
>>> That means that #if could ask anything for the compiler like sizeof
>>> of the variable on scope, or if a variable/function exists etc.
>>>
>>> Considering this.. I was wondering if the C language could change its
>>> concepts to allow this in the future.
>>>
>>> When we read code, we don't do the preprocessor "separated" in
>>> your mind we do it "on demand" as well.
>>>
>>> The invention of _Static_assert for instance would not be necessary
>>>
>>> Instead of
>>>
>>> _Static_assert( sizeof(x) == sizeof(int), "must be sizeof int");
>>>
>>> we could just write:
>>>
>>> #if sizeof(x) != sizeof(int)
>> This requires that the lexer knows about symbol tables, scopes and user
>> types, and that operations such as building those types and user types
>> and the name resolution required to figure out which x is intended, are
>> all done while parsing.
>
> The lexer ask questions direct to the compiler and the compiler has
> all the tables.
>
> compiler says : "give me the next token, in case you need ask me".
>
>
>> In other words, that part needs to be single pass, which puts a
>> constraint on the compiler.
>
> Yes, good point.
>
>> Also, what happens when someone /only/ wants to do a preprocessing pass?
>> Then 'sizeof(x)' is meaningless.
>
> Would be an error.
>
>> Would you have to remove that ability from the language? I think more
>> than a few compilers depend on a third party preprocessors, and various
>> language processing tools may depend on it too.
>>
>> So it's an unlikely retrofit for C.
>
> I think all the preprocessor is already very mixed with the compiler
> I have several samples.
>
> -C++ added digit separators and they had to change pp-number (preprocessor
> definition of number). You cannot use an external preprocessor that is
> not synchronized.

> -#pragma are used to control the compiler. what happen using an external preprocessor
> will just remove the content?

If an implementation doesn't understand what follows #pragma, then it
will just ignore it.

When it does understand it, it will just define some input, or set some
state, for the rest of the compiler to make use of. I don't think it
needs input from the compiler, or from later stages of it, unless you
have some examples?

When doing preprocessing only, then #pragma lines are passed unchanged.
(My compiler consumes them, so it's a bug, sort of. But there are worse
ones...)

> __func__ is already funny.

__func__ doesn't really belong in the processor. And actually it's a
predefined identifier, not a predefined macro.

If you try and use __func__ with -E, then you just get __func__. Which
means that when you try and compile that preprocessed output, /then/ it
will be expanded to the function name, if it's inside a function.

Re: Preprocessor <-> compiler

<cd93ffc7-8fd3-43de-b320-f70a993506d9n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18534&group=comp.lang.c#18534

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:484:: with SMTP id 4mr7011280qkr.409.1633288577138;
Sun, 03 Oct 2021 12:16:17 -0700 (PDT)
X-Received: by 2002:a05:622a:11d5:: with SMTP id n21mr10069842qtk.112.1633288576902;
Sun, 03 Oct 2021 12:16:16 -0700 (PDT)
Path: rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sun, 3 Oct 2021 12:16:16 -0700 (PDT)
In-Reply-To: <sjctg9$bim$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=189.6.249.78; posting-account=xFcAQAoAAAAoWlfpQ6Hz2n-MU9fthxbY
NNTP-Posting-Host: 189.6.249.78
References: <68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com>
<sjclfk$e3c$1@dont-email.me> <0e8f856f-696b-4f32-9b05-f44e04c2ffffn@googlegroups.com>
<sjctg9$bim$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <cd93ffc7-8fd3-43de-b320-f70a993506d9n@googlegroups.com>
Subject: Re: Preprocessor <-> compiler
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Sun, 03 Oct 2021 19:16:17 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 176
 by: Thiago Adams - Sun, 3 Oct 2021 19:16 UTC

On Sunday, October 3, 2021 at 3:41:24 PM UTC-3, Bart wrote:
> On 03/10/2021 18:55, Thiago Adams wrote:
> > On Sunday, October 3, 2021 at 1:24:32 PM UTC-3, Bart wrote:
> >> On 03/10/2021 14:47, Thiago Adams wrote:
> >>> I have implemented the preprocessor 'on demand' in my c compiler
> >>> front end and I was kind of regretting it because the code become
> >>> much more complex compared with preprocess in everything in
> >>> advance and separately.
> >>>
> >>> I was planning to change it to simplify the code but I realized that
> >>> this makes it possible the integration with the compiler.
> >>>
> >>> My parser asks 'give me the next token’ for a preprocessor state machine
> >>> and it returns only tokens already preprocessed.
> >>>
> >>> For instance:
> >>>
> >>> void F() {
> >>> char ch =
> >>> #if 0
> >>> 'a'
> >>> #else
> >>> 'b'
> >>> #endif
> >>> ;
> >>> }
> >>> after '=' the parser pulls the next token and the preprocessor move
> >>> its internal state consuming preprocessor tokens until it finds 'b' returning it’.
> >>>
> >>> It asks again and the preprocessor returns ';' changing it internal state
> >>> after consuming (but not returning) #endif.
> >>>
> >>> The internal state (#include, #ifdefs, #endif) are kept in stacks.
> >>> Macro expansion is on demand as well.
> >>>
> >>> This preprocessor state machine has an advantage.
> >>>
> >>> It still happens before the compiler phase but it has the compiler
> >>> context and could access it.
> >>>
> >>> That means that #if could ask anything for the compiler like sizeof
> >>> of the variable on scope, or if a variable/function exists etc.
> >>>
> >>> Considering this.. I was wondering if the C language could change its
> >>> concepts to allow this in the future.
> >>>
> >>> When we read code, we don't do the preprocessor "separated" in
> >>> your mind we do it "on demand" as well.
> >>>
> >>> The invention of _Static_assert for instance would not be necessary
> >>>
> >>> Instead of
> >>>
> >>> _Static_assert( sizeof(x) == sizeof(int), "must be sizeof int");
> >>>
> >>> we could just write:
> >>>
> >>> #if sizeof(x) != sizeof(int)
> >> This requires that the lexer knows about symbol tables, scopes and user
> >> types, and that operations such as building those types and user types
> >> and the name resolution required to figure out which x is intended, are
> >> all done while parsing.
> >
> > The lexer ask questions direct to the compiler and the compiler has
> > all the tables.
> >
> > compiler says : "give me the next token, in case you need ask me".
> >
> >
> >> In other words, that part needs to be single pass, which puts a
> >> constraint on the compiler.
> >
> > Yes, good point.
> >
> >> Also, what happens when someone /only/ wants to do a preprocessing pass?
> >> Then 'sizeof(x)' is meaningless.
> >
> > Would be an error.
> >
> >> Would you have to remove that ability from the language? I think more
> >> than a few compilers depend on a third party preprocessors, and various
> >> language processing tools may depend on it too.
> >>
> >> So it's an unlikely retrofit for C.
> >
> > I think all the preprocessor is already very mixed with the compiler
> > I have several samples.
> >
> > -C++ added digit separators and they had to change pp-number (preprocessor
> > definition of number). You cannot use an external preprocessor that is
> > not synchronized.
>
> > -#pragma are used to control the compiler. what happen using an external preprocessor
> > will just remove the content?
> If an implementation doesn't understand what follows #pragma, then it
> will just ignore it.

Yes but if you think a traditional preprocessor that runs before and generate a file that
latter will be the input for the compiler then the #pragma is removed (empty line) when the file
is printed and the compiler will not have access to it.

Having the preprocessor integrated can keep #pragma in tokens (with internal representation)
and latter discard or use it.


> When it does understand it, it will just define some input, or set some
> state, for the rest of the compiler to make use of. I don't think it
> needs input from the compiler, or from later stages of it, unless you
> have some examples?

When the preprocessor is from the same compiler I think some tokens generated
by pragmas are used to control the compiler.. like disabling warnings.
(I am not sure If I understood the question)


> When doing preprocessing only, then #pragma lines are passed unchanged.
> (My compiler consumes them, so it's a bug, sort of. But there are worse
> ones...)
>
> > __func__ is already funny.
>
> __func__ doesn't really belong in the processor. And actually it's a
> predefined identifier, not a predefined macro.

yes... this is why it is funny. it is like a macro expansion by the compiler.


> If you try and use __func__ with -E, then you just get __func__. Which
> means that when you try and compile that preprocessed output, /then/ it
> will be expanded to the function name, if it's inside a function.

There is more ..

now C23 has attributes and we can ask if the compiler support it:

#if __has_c_attribute(nodiscard)
yes
#endif

-E returns yes.

not difficult to implement, but shows preprocessor and compiler are
interdependent.
If the information required by the preprocessor from the compiler is
static then everything is easy. sizeof(int) for instance could be
implemented easily if necessary, but sizeof(variable) not.

Re: Preprocessor <-> compiler

<sjd09h$t1$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18535&group=comp.lang.c#18535

  copy link   Newsgroups: comp.lang.c
Path: rocksolid2!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Preprocessor <-> compiler
Date: Sun, 3 Oct 2021 20:28:46 +0100
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <sjd09h$t1$1@dont-email.me>
References: <68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com>
<sjclfk$e3c$1@dont-email.me>
<0e8f856f-696b-4f32-9b05-f44e04c2ffffn@googlegroups.com>
<sjctg9$bim$1@dont-email.me>
<cd93ffc7-8fd3-43de-b320-f70a993506d9n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 3 Oct 2021 19:28:49 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="61dedff8bdc4cd6e2c4ae53830bb2ffd";
logging-data="929"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yym1WI1ZZdduv9t8rFEhFPcYmItuz/8Q="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:Kxuk9bK9c91W3Wyf+VLyqt5ZBjc=
In-Reply-To: <cd93ffc7-8fd3-43de-b320-f70a993506d9n@googlegroups.com>
X-Antivirus-Status: Clean
Content-Language: en-GB
X-Antivirus: AVG (VPS 211003-10, 3/10/2021), Outbound message
 by: Bart - Sun, 3 Oct 2021 19:28 UTC

On 03/10/2021 20:16, Thiago Adams wrote:
> On Sunday, October 3, 2021 at 3:41:24 PM UTC-3, Bart wrote:

>>> -#pragma are used to control the compiler. what happen using an external preprocessor
>>> will just remove the content?
>> If an implementation doesn't understand what follows #pragma, then it
>> will just ignore it.
>
> Yes but if you think a traditional preprocessor that runs before and generate a file that
> latter will be the input for the compiler then the #pragma is removed (empty line) when the file
> is printed and the compiler will not have access to it.

No, I said the compiler keeps it in. (Well, I tried gcc, tcc, clang and
lccwin which did, and bcc which didn't.)

Probably precisely for that reason.

>

> yes... this is why it is funny. it is like a macro expansion by the compiler.

In my language this stuff is done by the parser anyway.

> If the information required by the preprocessor from the compiler is
> static then everything is easy. sizeof(int) for instance could be
> implemented easily if necessary, but sizeof(variable) not.

sizeof(int) maybe, but probably not sizeof(int32_t). First this will
require headers to be present, that's OK, but int32_t is likely to be a
typedef.

However this rings a bell ... yes, I've put sizeof() into my own
preprocessor, so that this is possible:

#if sizeof(int) == 4

but with the aforementioned problems using int32_t.

Re: Preprocessor <-> compiler

<87zgrpg6d8.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18538&group=comp.lang.c#18538

  copy link   Newsgroups: comp.lang.c
Path: rocksolid2!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Preprocessor <-> compiler
Date: Sun, 03 Oct 2021 14:12:35 -0700
Organization: None to speak of
Lines: 27
Message-ID: <87zgrpg6d8.fsf@nosuchdomain.example.com>
References: <68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com>
<sjclfk$e3c$1@dont-email.me>
<0e8f856f-696b-4f32-9b05-f44e04c2ffffn@googlegroups.com>
<sjctg9$bim$1@dont-email.me>
<cd93ffc7-8fd3-43de-b320-f70a993506d9n@googlegroups.com>
<sjd09h$t1$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="c2d6cdc050f73b1d409dee830d1f9cb0";
logging-data="6399"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Ox+YtCPwxKYeEL6AKbFPa"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:A6JAukHAQClNB4vYpqngLLu+jTM=
sha1:fpJBM2N1oUeTbOfXMxXXW/WOjVs=
 by: Keith Thompson - Sun, 3 Oct 2021 21:12 UTC

Bart <bc@freeuk.com> writes:
[...]
> However this rings a bell ... yes, I've put sizeof() into my own
> preprocessor, so that this is possible:
>
> #if sizeof(int) == 4
>
> but with the aforementioned problems using int32_t.

From a comp.std.c post in 1998:

> You are right. It was nice back in the days when things like
>
> #if (sizeof(int) == 8)
>
> actually worked (on some compilers).

Must have been before my time.

Dennis

Yes, the poster was Dennis Ritchie.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Preprocessor <-> compiler

<sjkg2p$lc7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18589&group=comp.lang.c#18589

  copy link   Newsgroups: comp.lang.c
Path: rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: Preprocessor <-> compiler
Date: Wed, 6 Oct 2021 08:41:13 -0700
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <sjkg2p$lc7$1@dont-email.me>
References: <68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 6 Oct 2021 15:41:13 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="eff7dbf1fcddb7e8267634a997988dba";
logging-data="21895"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HoKN8RJU3/5kSdy9H+pwk"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:jK/1GMkSI08p4wq88EjjVPkfZiA=
In-Reply-To: <68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com>
Content-Language: en-US
 by: Andrey Tarasevich - Wed, 6 Oct 2021 15:41 UTC

On 10/3/2021 6:47 AM, Thiago Adams wrote:
>
> It still happens before the compiler phase but it has the compiler
> context and could access it.
>

You are trying to invent C++'s `if constexpr` or some subset thereof.
The topic is sufficiently well researched. I just don't see any reason
to pin all this on "preprocessor".

--
Best regards,
Andrey Tarasevich

Re: Preprocessor <-> compiler

<40790732-9bb0-43be-b38b-084dcbff0386n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=18595&group=comp.lang.c#18595

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:554a:: with SMTP id v10mr26356051qvy.29.1633542991045;
Wed, 06 Oct 2021 10:56:31 -0700 (PDT)
X-Received: by 2002:ac8:7748:: with SMTP id g8mr69105qtu.281.1633542990853;
Wed, 06 Oct 2021 10:56:30 -0700 (PDT)
Path: rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 6 Oct 2021 10:56:30 -0700 (PDT)
In-Reply-To: <sjkg2p$lc7$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=189.6.249.78; posting-account=xFcAQAoAAAAoWlfpQ6Hz2n-MU9fthxbY
NNTP-Posting-Host: 189.6.249.78
References: <68d48f9f-4268-47e4-8728-a158cbf9c2ccn@googlegroups.com> <sjkg2p$lc7$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <40790732-9bb0-43be-b38b-084dcbff0386n@googlegroups.com>
Subject: Re: Preprocessor <-> compiler
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Wed, 06 Oct 2021 17:56:31 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 24
 by: Thiago Adams - Wed, 6 Oct 2021 17:56 UTC

On Wednesday, October 6, 2021 at 12:41:21 PM UTC-3, Andrey Tarasevich wrote:
> On 10/3/2021 6:47 AM, Thiago Adams wrote:
> >
> > It still happens before the compiler phase but it has the compiler
> > context and could access it.
> >
> You are trying to invent C++'s `if constexpr` or some subset thereof.
> The topic is sufficiently well researched. I just don't see any reason
> to pin all this on "preprocessor".

To be used together with #if .

C++ 'if constexpr' can be used only where if can.

D has static if that can be used in more places.

https://dlang.org/spec/version.html#staticif

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor