In this question, the current C solution is
f(n){n=n?:1;}
Obviously this command line is shorter by 2 bytes:
-Df(n)=n?:1
But I've never seen anyone do that.
Is it allowed but not found, or not allowed? In the latter case, why?
In this question, the current C solution is
f(n){n=n?:1;}
Obviously this command line is shorter by 2 bytes:
-Df(n)=n?:1
But I've never seen anyone do that.
Is it allowed but not found, or not allowed? In the latter case, why?
Passing -Df(n)!n+n
to the compiler is exactly equivalent to adding #define f(n)!n+n
in the code. So there is no reason to allow one and disallow the other.
Apparently no one wrote an answer...
For those who are not familiar with the language C:
The "accepted" solution, use #define
, add 16 bytes (17 if the newline is counted) to the file to define the function:
#define f(n)!n+n
int main() {
printf("%d\n%d", f(0), f(5));
}
and the command to compile it: (assume the file is stored as a.c
)
gcc a.c
(which will produce an executable named a
. It's possible to specify executable name with -o
, but it's not important here)
where the proposed solution would add 0 byte to the file:
int main() {
printf("%d\n%d", f(0), f(5));
}
but make the compilation command 11 bytes longer:
gcc -Df(n)!n+n a.c
-Df(n)=xxx
and -Df(n)xxx
go different, though the latter can be used to save more bytes in this problem
\$\endgroup\$
There are conflicting accounts on how to score command line arguments and flags however, everyone seems to agree (for the most part) that the use of any and all command line flags is allowed. So yes, you can use flags to set C macros.
The but part of this answer is scoring. Traditionally scoring command line flags has been a muddy ordeal, there was a meta answer which was interpreted in different ways by different people and lead to a lot of confusion. Under that method you would probably have to add either 10 or 11 bytes to your score for the flag.
Recently there has been a push to stop scoring command line flags altogether. Different flags are different invocations of the interpreter and thus are different languages. This is nice for a couple of reasons, the main one is it is completely unambiguous. Mego's post here and my question here outline the reasons for this in better detail. Under this system you would gain 0 bytes for using the flag, but would have to mark it as a separate language.
This is basically the same as saying don't do that. There is not much sense in making that answer because, since most competitions are language categorized, you are only competing against yourself.
I'm still not convinced that this works: the TIO link for the answer you refer to shows that it is buggy. But that's really an aside. To address the real question:
To get a macro equivalent to
f(n){n=n?:1;}
you need
-Df(n)=((n)?:1)
which is longer, so there's no point.
What's a function
\$\endgroup\$
-x
as +1B but modifyer treat it as 2? \$\endgroup\$n?n:1
\$\endgroup\$