Damn you C language and all it's compilers!
-
The following compiles cleanly with no warnings:
void die() {}
int main()
{
die(1,2,3);
}Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition -
The following compiles cleanly with no warnings:
void die() {}
int main()
{
die(1,2,3);
}Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth EditionI'm not allowed to answer progging questions here, otherwise I'd tell you... ;P
Wout
-
The following compiles cleanly with no warnings:
void die() {}
int main()
{
die(1,2,3);
}Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth EditionMaybe die has been defined somewhere else? Maybe your not including the standard libraries correctly. Maybe your compiler is not strict. Could be anything. Hell could be even having an extra line return at the end of your code. :laugh:
"I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones." Einstein "Few things are harder to put up with than the annoyance of a good example." Mark Twain
-
Maybe die has been defined somewhere else? Maybe your not including the standard libraries correctly. Maybe your compiler is not strict. Could be anything. Hell could be even having an extra line return at the end of your code. :laugh:
"I do not know with what weapons World War 3 will be fought, but World War 4 will be fought with sticks and stones." Einstein "Few things are harder to put up with than the annoyance of a good example." Mark Twain
VectorX wrote:
Maybe die has been defined somewhere else?
No, it does the same if it is called
do_shit
. Edit: I spy the word filter not doing it's job!xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition -
The following compiles cleanly with no warnings:
void die() {}
int main()
{
die(1,2,3);
}Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth EditionBecause in C an empty parameter list means "unspecified parameters", while
void die(void)
means exactly zero parameters. It's one of the things that changed from C to C++. That said, I would have expected at least a warning too.Luca The Price of Freedom is Eternal Vigilance. -- Wing Commander IV En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur. (But the best thing God has created, is a New Day.) -- Sigur Ròs - Viðrar vel til loftárása
-
Because in C an empty parameter list means "unspecified parameters", while
void die(void)
means exactly zero parameters. It's one of the things that changed from C to C++. That said, I would have expected at least a warning too.Luca The Price of Freedom is Eternal Vigilance. -- Wing Commander IV En Það Besta Sem Guð Hefur Skapað, Er Nýr Dagur. (But the best thing God has created, is a New Day.) -- Sigur Ròs - Viðrar vel til loftárása
Luca Leonardo Scorcia wrote:
void die(void)
Ahh, so that is why I see the 'explicit'
void
in the param list. I always though was just pedantic leftovers from the trigraph era ;P Now to go change all my declarations to have the proper intent. PS: How can you get the variables passed (eg the 1,2,3 in my example)? Withva_args
?xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition -
Luca Leonardo Scorcia wrote:
void die(void)
Ahh, so that is why I see the 'explicit'
void
in the param list. I always though was just pedantic leftovers from the trigraph era ;P Now to go change all my declarations to have the proper intent. PS: How can you get the variables passed (eg the 1,2,3 in my example)? Withva_args
?xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth EditionEr, erm, scrtathces head, cant remember, got sokm ecode of mine that does this, and uses va_start() and va_end() to pull them apart (or at least somehting like this). Its gotta be in ths SDK somewhere though!
Morality is indistinguishable from social proscription
-
Er, erm, scrtathces head, cant remember, got sokm ecode of mine that does this, and uses va_start() and va_end() to pull them apart (or at least somehting like this). Its gotta be in ths SDK somewhere though!
Morality is indistinguishable from social proscription
fat_boy wrote:
Er, erm, scrtathces head, cant remember, got sokm ecode of mine that does this, and uses va_start() and va_end() to pull them apart (or at least somehting like this).
Usage is a not problem. You use them anyways with
...
parameters.xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition -
The following compiles cleanly with no warnings:
void die() {}
int main()
{
die(1,2,3);
}Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition -
fat_boy wrote:
Er, erm, scrtathces head, cant remember, got sokm ecode of mine that does this, and uses va_start() and va_end() to pull them apart (or at least somehting like this).
Usage is a not problem. You use them anyways with
...
parameters.xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth EditionYeah, thats the most common way pf passing a load of junk around. The final handling func can use the va_xxx() funcs if you like, or you can pull the stack apart yourself if you like! (Or just want a bit of pain)
Morality is indistinguishable from social proscription
-
S. Becker wrote:
warning level -4 ?
There is no -4 option ;P But yeah, not even level 4 does it.
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition -
Luca Leonardo Scorcia wrote:
void die(void)
Ahh, so that is why I see the 'explicit'
void
in the param list. I always though was just pedantic leftovers from the trigraph era ;P Now to go change all my declarations to have the proper intent. PS: How can you get the variables passed (eg the 1,2,3 in my example)? Withva_args
?xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth EditionWell, actually, an empty parameter list is leftovers from when C didn't really do formal parameter lists and you declared functions as (if memory serves):
int some_function()
int param1;
int param2;
{
do stuff
}And trigraphs are still just about alive and well in the C++ standard currently out for ballot, I think you'll find ;-)
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p CodeProject MVP for 2010 - who'd'a thunk it!
-
VectorX wrote:
Maybe die has been defined somewhere else?
No, it does the same if it is called
do_shit
. Edit: I spy the word filter not doing it's job!xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth EditionWell there's your problem.
.45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
The following compiles cleanly with no warnings:
void die() {}
int main()
{
die(1,2,3);
}Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth EditionHP C V7.3-009 on OpenVMS Alpha V8.3 says:
JB> cc CTEST.C
die(1,2,3);
....^
%CC-I-TOOMANYARGSO, In this statement, "die", which was declared with an old-style function definition, expects 0 arguments, but 3 a
re supplied.
at line number 5 in file MY$ROOT:[000000]CTEST.C;1JB> cc CTEST.C /warning=verbose
die(1,2,3);
....^
%CC-I-TOOMANYARGSO, In this statement, "die", which was declared with an old-style function definition, expects 0 arguments, but 3 a
re supplied.
at line number 5 in file MY$ROOT:[000000]CTEST.C;1
Description: A function that was declared with an old-style function definition has been invoked with more arguments than it expects
. While this is valid C, it might not have been what you intended.
User Action: Make sure the number of arguments passed to a function match those specified in the function declaration. If the funct
ion is to be called with a variable number of arguments, it should use the facilities of <varargs.h> for old-style definitions. HP
generally recommends that old-style function definitions be replaced by prototype-format definitions, in which case variable argumen
t lists are specified using the ... notation and the definition uses the facilities of <stdarg.h>.You owe HP an apology. :-D
-
The following compiles cleanly with no warnings:
void die() {}
int main()
{
die(1,2,3);
}Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth EditionAs others have said it's valid, but only for historical reasons. Use a construct like that and C will assume that you know what you're doing and leave you to it. Even if the compiler didn't warn you, lint will if you use it:
FlexeLint for C/C++ (Unix) Vers. 9.00d8, Copyright Gimpel Software 1985-2010
--- Module: offbyone.c (C)
1 void die() {}
2
3 int main()
4 {
_
5 die(1,2,3);
offbyone.c 5 Error 119: Too many arguments (3) for prototype 'die(void)'
offbyone.c 5 Warning 522: Highest operation, function 'die', lacks side-effectsYou can try it yourself using Gimpel's online demonstrators for C[^] and C++[^]. :cool:
Anna :rose: Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"
-
As others have said it's valid, but only for historical reasons. Use a construct like that and C will assume that you know what you're doing and leave you to it. Even if the compiler didn't warn you, lint will if you use it:
FlexeLint for C/C++ (Unix) Vers. 9.00d8, Copyright Gimpel Software 1985-2010
--- Module: offbyone.c (C)
1 void die() {}
2
3 int main()
4 {
_
5 die(1,2,3);
offbyone.c 5 Error 119: Too many arguments (3) for prototype 'die(void)'
offbyone.c 5 Warning 522: Highest operation, function 'die', lacks side-effectsYou can try it yourself using Gimpel's online demonstrators for C[^] and C++[^]. :cool:
Anna :rose: Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"
Thanks, will check it out :)
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition -
The following compiles cleanly with no warnings:
void die() {}
int main()
{
die(1,2,3);
}Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Editiong++ compiler considers it an error, not even a warning:
error: too many arguments to function `void MyNamespace::die()'
Run from NetBeans, via MinGW environment on Windows. Not sure about options: I use defaults.
-
Thanks, will check it out :)
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth EditionHave fun. :) It's a very powerful too, although it does take a while to get the hang of using it effectively.
Anna :rose: Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"
-
The following compiles cleanly with no warnings:
void die() {}
int main()
{
die(1,2,3);
}Does not work in C++ though. Why on earth would no C compiler (linker rather) (I tested MSVC and some embedded C compiler) emit a simple warning? X|
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth EditionHi! By default, if You write the prototype without any parameters in parenthesis, as in: void die() {}, then C compiler assumes that is such a function You can pass ANY number (of any type) of parameters; If You wish to have a function which will NOT receive any parameter, then, You have to write void die(void){}; (mark the word VOID in the function's parameter list) When C++ or Java is in the concern, then, the empty parenthesis mean that this is the function which does NOT accept the parameters in list; In C++ You can set void in parenthesis, but it is not mandatory. Best regards!
-
g++ compiler considers it an error, not even a warning:
error: too many arguments to function `void MyNamespace::die()'
Run from NetBeans, via MinGW environment on Windows. Not sure about options: I use defaults.
We have covered the fact that it wont compile as C++. Call gcc directly.
xacc.ide
IronScheme - 1.0 RC 1 - out now!
((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition