Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: configure() -- a new C compiler preprocessor and code injection proposal Date: Sun, 23 Aug 2015 14:27:49 -0700 Organization: None to speak of Lines: 54 Message-ID: References: <93b0ff7b-6ee2-48f9-aad4-6e3b91e9ceac@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="9317"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19JeoW0XGc1GK2ZHL4GtEao" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:sIARhIogP9KzTUrctnxVPjs7UdI= sha1:CVbvcsnXhJ0kRBz9O9oma+fubLQ= Xref: csiph.com comp.lang.c:68146 "Morten W. Petersen" writes: > On 23.08.2015 14:35, Bartc wrote: >> On 23/08/2015 13:27, Morten W. Petersen wrote: >>> On 23.08.2015 14:03, Bartc wrote: [...] >>>> How would it replace a macro like this: >>>> >>>> #define FOR(i,a,b) for(i=a; i<=b; ++i) >>>> >>>> (And at what stage do all FOR invocations in the source get expanded?) >>>> >>>> Macros with arguments are an important part of C. I don't think you can >>>> remove them without replacing them with something that can do the same >>>> things. And in the case of macros such as the above, I can't see the >>>> definition looking much different, or being less effort to implement. >>> >>> Couldn't that be replaced by an inline function? >> >> Not this example, because it's not an expression, but a piece of syntax. >> The invocation would be followed by {...}, a single statement; or ";". > > Are there any cases for macros where they couldn't be replaced by > functions? Like it would be many more lines of code to do something > similar in C code. I'm probably misunderstanding the question, because the obvious answer is that you've just seen an example of a macro that cannot be replaced by a function, inline or otherwise. (Conceivably you could write an inline function that takes a function pointer as an argument, with the function acting as the body of the loop -- but the function would have to be defined separately, and its body would not be in the scope of the loop.) > A point about the macros is that they are different than regular C > code, and because of that an added point of complexity / confusion. And added capabilities. > So a new programmer wouldn't have to learn macros in a variant of > C that drops that support. And another template language could > be used for simple or not so simple substitutions. C already has a template language, the preprocessor. What is the advantage of replacing that with a *different* template language? Even if you decide to do that, there's no real need to incorporate it into the language. Tools that generate C code are already quite common, and can be invoked automatically by any build system. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"