Yes, I know it's 2016
-
but I just devised a cunning C macro. :cool: I may not be the first to devise this, but I'm likely the only one this decade. Many-a-day in years past I bemoaned that the
argv
array includes the name of the running executable and the resultant off-by-one confusion it caused me. So I was over-joyed to see that C# does away with that nonsense. Then today I was dabbling in some minor C code and so my depression returned. It occurred to me that all I wanted was something like theSHIFT
command (DOS), so after a few minutes' thought, I wrote:# define SHIFT (++argv,--argc)
I wrote it that way so it can be used in either of the following ways:
SHIFT ;
if ( argc > 0 ) { ... }
while ( SHIFT > 0 ) { ... }
switch ( SHIFT )
{
case 0 : { ... ; break ; }
case 1 : { ... ; break ; }
case 2 : { ... ; break ; }
...
default : { ... ; break ; }
}:badger:
-
but I just devised a cunning C macro. :cool: I may not be the first to devise this, but I'm likely the only one this decade. Many-a-day in years past I bemoaned that the
argv
array includes the name of the running executable and the resultant off-by-one confusion it caused me. So I was over-joyed to see that C# does away with that nonsense. Then today I was dabbling in some minor C code and so my depression returned. It occurred to me that all I wanted was something like theSHIFT
command (DOS), so after a few minutes' thought, I wrote:# define SHIFT (++argv,--argc)
I wrote it that way so it can be used in either of the following ways:
SHIFT ;
if ( argc > 0 ) { ... }
while ( SHIFT > 0 ) { ... }
switch ( SHIFT )
{
case 0 : { ... ; break ; }
case 1 : { ... ; break ; }
case 2 : { ... ; break ; }
...
default : { ... ; break ; }
}:badger:
:cool: I don't use C (or C++) much, though.
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
-
:cool: I don't use C (or C++) much, though.
What do you get when you cross a joke with a rhetorical question? The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism. Do questions with multiple question marks annoy you???
Nor do I.
-
but I just devised a cunning C macro. :cool: I may not be the first to devise this, but I'm likely the only one this decade. Many-a-day in years past I bemoaned that the
argv
array includes the name of the running executable and the resultant off-by-one confusion it caused me. So I was over-joyed to see that C# does away with that nonsense. Then today I was dabbling in some minor C code and so my depression returned. It occurred to me that all I wanted was something like theSHIFT
command (DOS), so after a few minutes' thought, I wrote:# define SHIFT (++argv,--argc)
I wrote it that way so it can be used in either of the following ways:
SHIFT ;
if ( argc > 0 ) { ... }
while ( SHIFT > 0 ) { ... }
switch ( SHIFT )
{
case 0 : { ... ; break ; }
case 1 : { ... ; break ; }
case 2 : { ... ; break ; }
...
default : { ... ; break ; }
}:badger:
-
Is this for some place where you can't use getopt? (like not supported by the compiler, or want to keep the binary size small?)
No, but I expect it can be used with it if you want, but that looks dreadful.
-
No, but I expect it can be used with it if you want, but that looks dreadful.
That was exactly my thought when I looked at getopt, but its somehow become the established standard for command-line processing on Unix-like systems. But then, that's elegant compared to the dog's do-do that is autoconf and the m4 macro-processor. Shudders.
"If you don't fail at least 90 percent of the time, you're not aiming high enough." Alan Kay.