G
Grey Plastic
I'm looking for a way to declare variables inside for statements (or
perhaps some other statement) and have the following statement execute
exactly once. For example,
for(Type var=blah; 1; )
would be what I wanted, if it ran only once, instead of forever.
Similarly,
if(Type var=blah)
would be what I wanted if the statement following it ran even when
blah evaluated as false.
What I'm attempting to do is write my own for-loop style interface
using defines. For example, I want to write something like
#define CUSTOM_FOR_BEGIN(x,y,var) \
for(int x=0; x<256; x++) \
for(int y=0; y<256; y++) { \
Type var = blah;
#define CUSTOM_FOR_END() }
But I want to omit the CUSTOM_FOR_END part. I want something like
#define CUSTOM_FOR(x,y,var) \
for(int x=0; x<256; x++) \
for(int y=0; y<256; y++) \
for(Type var = blah; runOnce; )
so that I can have code like
CUSTOM_FOR(i,j,whee)
foo(whee,j);
and
CUSTOM_FOO(i,j,whee) {
foo(whee,j);
bar(j,i);
}
I'm using GNU C++, and am totally cool with using GNU extensions.
perhaps some other statement) and have the following statement execute
exactly once. For example,
for(Type var=blah; 1; )
would be what I wanted, if it ran only once, instead of forever.
Similarly,
if(Type var=blah)
would be what I wanted if the statement following it ran even when
blah evaluated as false.
What I'm attempting to do is write my own for-loop style interface
using defines. For example, I want to write something like
#define CUSTOM_FOR_BEGIN(x,y,var) \
for(int x=0; x<256; x++) \
for(int y=0; y<256; y++) { \
Type var = blah;
#define CUSTOM_FOR_END() }
But I want to omit the CUSTOM_FOR_END part. I want something like
#define CUSTOM_FOR(x,y,var) \
for(int x=0; x<256; x++) \
for(int y=0; y<256; y++) \
for(Type var = blah; runOnce; )
so that I can have code like
CUSTOM_FOR(i,j,whee)
foo(whee,j);
and
CUSTOM_FOO(i,j,whee) {
foo(whee,j);
bar(j,i);
}
I'm using GNU C++, and am totally cool with using GNU extensions.