This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: A##B a preprocessing token?
- To: Jiri Kolafa <jiri at icpf dot cas dot cz>
- Subject: Re: A##B a preprocessing token?
- From: Carlo Wood <carlo at alinoe dot com>
- Date: Tue, 6 Nov 2001 17:40:42 +0100
- Cc: gcc-bugs at gcc dot gnu dot org
- References: <Pine.OSF.4.10.10111061539040.23366-100000@omega>
On Tue, Nov 06, 2001 at 04:26:07PM +0100, Jiri Kolafa wrote:
> I have used for years a construct that translates
> loop (i,from,to)
> into
> for (i=from; i<to; i++)
> and at the same time
> loop (i,from,=to)
> into
> for (i=from; i<=to; i++)
This doesn't seem a good reason to remove the warning:
It is an ugly way of programming and deserves a
warning imho (disclaimer: I am not a gcc developer).
Nevertheless, let me suggest something to chance your
code so that it will work again. You could use
loop (i,from,<to) and loop (i,from,<=to)
or
loop_till (i,from,to) and
loop_till_and_including(i,from,to).
or you could use
for (i=from; i<to; i++) and
for (i=from; i<=to; i++)
of course.
Or you could use an inline function instead of a macro:
#include <stdio.h>
enum what_nt { till, till_plus };
__inline__ void loop(int from, enum what_nt what, int to, void (*func_body)(int))
{
if (what == till_plus)
++to;
int i = from;
while(i < to)
{
func_body(i);
++i;
}
}
void func(int i)
{
printf("%d\n", i);
}
int main(void)
{
loop(1, till, 4, func);
loop(1, till_plus, 4, func);
return 0;
}
--
Carlo Wood <carlo@alinoe.com>