Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #103419

Re: Preprocessor expressions

From BartC <bc@freeuk.com>
Newsgroups comp.lang.c
Subject Re: Preprocessor expressions
Date 2017-02-07 21:01 +0000
Organization A noiseless patient Spider
Message-ID <o7dcfu$69q$1@dont-email.me> (permalink)
References (7 earlier) <e3c53979-10e8-44e4-b6c4-0cd5b65ae78f@googlegroups.com> <4bb1dbcd-6e3c-40df-8319-eb33b8bfa685@googlegroups.com> <030e3613-d745-46c4-8a46-d625eb276baa@googlegroups.com> <o7a3u7$9u$1@dont-email.me> <1e988be1-ec21-4335-8f79-e6d1e213f1c7@googlegroups.com>

Show all headers | View raw


On 07/02/2017 13:36, Thiago Adams wrote:
> On Monday, February 6, 2017 at 1:17:14 PM UTC-2, Bart wrote:

>> One idea I might try out, is to only output declarations from stdio.h
>> that are used in the program (either directly on indirectly). For
>> hello.c, that means declaring printf().
>>
>> But the user program can still have this:
>>
>>   #if cond
>>     printf("hello");
>>   #endif
>>
>> For my purposes, everything will need to be preprocessed anyway, so
>> printf will be included when cond is true. The output will be C code
>> that doesn't use any headers, not even system ones.
>
> I guess, that you can increase the changes of avoiding "rebuild" in
> different platforms if you keep the include of the system headers.
> For instance, let's say you have a simple hello world.
>
> #include <stdio.h>
>
> int main()
> {
>   printf("hello");
> }
>
> The generated code is the same. But if you include the declarations of
> stdio.h you may be including a lot of stuffs from the previous platform.

Yes, quite a lot of stuff will be fixed in the output C source, 
restricting how it can be used.

My experience at the moment (translating from a non-C language to C, in 
a recent working project) is that things such as pointer sizes, and 
struct-member offsets, will be fixed. That means that generated C 
requires things like pack(1), and to be compiled for a particular 
pointer size.

I'm not familiar with the details of the standard headers so I don't yet 
know what other issues will arise. However, my current project counts as 
a compiler, and a compiler is allowed to make these decisions as they 
will usually have a particular target in mind.

It just means that if it optionally writes out the program code as C 
source (rather than binary native code or ASM source, tied to some 
processor and ABI), then it may be similarly restricted. I will have to 
see how to works out.

Keeping the output C general is a much harder project.

> I think the C standard also allow some functions to be implemented
> optionally as a macro and this can differs between platforms.
> If the "rebuild" is always used this is not a problem.
>
> Bart, what kind of "input source" do you have in mind?
> Language extensions for C? What kind?

For the new project, input source will be standard C code. One of the 
output options will be C, including single-file C. (Which may be 
restricted to run on the same platform it was generated on.)

I'm not looking at any extensions at the minute (for one thing, because 
I'm trying to make it fast, and any extensions are likely to slow to down!)

But later on, I'm likely to play around with some, although my ideas of 
worthwhile extensions are going to be different from yours, gcc's, or 
anyone else's.

-- 
bartc

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Preprocessor expressions BartC <bc@freeuk.com> - 2017-01-22 13:24 +0000
  Re: Preprocessor expressions jameskuyper@verizon.net - 2017-01-22 07:52 -0800
    Re: Preprocessor expressions Ralf Damaschke <rwspam@gmx.de> - 2017-01-22 17:15 +0000
      Re: Preprocessor expressions "James R. Kuyper" <jameskuyper@verizon.net> - 2017-01-22 13:32 -0500
    Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-01-22 17:38 +0000
      Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-01 03:12 -0800
        Re: Preprocessor expressions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-01 11:44 +0000
        Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-01 11:56 +0000
        Re: Preprocessor expressions jameskuyper@verizon.net - 2017-02-01 08:35 -0800
          Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-02 09:23 -0800
            Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-02 18:14 +0000
              Re: Preprocessor expressions Keith Thompson <kst-u@mib.org> - 2017-02-02 10:35 -0800
              Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-02 17:09 -0800
                Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-05 10:09 -0800
                Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-05 10:38 -0800
                Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-05 11:03 -0800
                Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-06 15:17 +0000
                Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-07 05:36 -0800
                Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-07 21:01 +0000
                Re: Preprocessor expressions supercat@casperkitty.com - 2017-02-07 13:16 -0800
                Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-07 22:09 +0000
                Re: Preprocessor expressions supercat@casperkitty.com - 2017-02-07 14:33 -0800
                Re: Preprocessor expressions Keith Thompson <kst-u@mib.org> - 2017-02-07 14:52 -0800
                Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-08 00:13 +0000
                Re: Preprocessor expressions Keith Thompson <kst-u@mib.org> - 2017-02-07 16:39 -0800
                Re: Preprocessor expressions jameskuyper@verizon.net - 2017-02-07 16:47 -0800
                Re: Preprocessor expressions David Brown <david.brown@hesbynett.no> - 2017-02-08 10:03 +0100
                Re: Preprocessor expressions Keith Thompson <kst-u@mib.org> - 2017-02-08 09:19 -0800
                Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-08 12:35 -0800
                Re: Preprocessor expressions Thiago Adams <thiago.adams@gmail.com> - 2017-02-09 05:25 -0800
                Re: Preprocessor expressions supercat@casperkitty.com - 2017-02-09 07:37 -0800
                Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-02-09 15:52 +0000
  Re: Preprocessor expressions BartC <bc@freeuk.com> - 2017-01-22 19:34 +0000
    Re: Preprocessor expressions jameskuyper@verizon.net - 2017-01-22 13:01 -0800
  Re: Preprocessor expressions Tim Rentsch <txr@alumni.caltech.edu> - 2017-01-30 05:30 -0800

csiph-web