This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: A##B a preprocessing token?


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>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]