I am reading an old book about code obfuscation in C (the book was printed in 1993), and I've noticed that the functions with arguments are implemented this way:
real_dump(address, infunc, ofp)
char *address;
int (*infunc)();
FILE *ofp;
{
/* the code goes here... */
}
Also, no return type is defined.
Is it an old standard? Is it possible to enable gcc to compile this code?
Hence, we conclude that Python Function Arguments and its three types of arguments to functions. These are- default, keyword, and arbitrary arguments. Where default arguments help deal with the absence of values, keyword arguments let us use any order.
There are two ways to pass arguments to a function: by reference or by value. Modifying an argument that's passed by reference is reflected globally, but modifying an argument that's passed by value is reflected only inside the function.
In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined. "The next biggest type" would actually be short .
The function body has three parts: an optional declarative part, an executable part, and an optional exception-handling part.
Function definitions in the non-prototype form are valid C89, C99 and C11 code.
It is called the old-style function definition but this feature is marked since C89 as an obsolescent feature.
This form should be not used in new programs.
C99 Rationale says:
"Characterizing the old style as obsolescent is meant to discourage its use and to serve as a strong endorsement by the Committee of the new style."
even K&R2 discourages its use:
"The old style of declaration and definition still works with ANSI C, at least for a transition period, but we strongly recommend that you use the new form when you have a compiler that supports it."
Now your function also doesn't have a return type and omitting the return type in a function declaration or in a function definition is no longer valid since C99. Before C99, functions without a return type implicitely returned an int
.
Regarding the gcc
question, by default gcc
compiles with -std=gnu89
. It means C89 Standard + gcc extensions. So by default gcc
will accept to compile a program with the functions declaration and definition in their old-style form and without a return type.
Ouch, this was the pre-ANSI C way to define functions, I really don't recommend using this kind of syntax in "normal" code. Still, gcc seems to accept it without problems (it's still in the standard, although marked as "obsolescent" in §6.11.7).
(by the way, as for the "missing" return type the "implicit int
rule" should apply)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With