473,385 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

gcc doesn't warn about calling a nullary function WITH parameters?

Can anyone tell me, why in the blazes GCC (e.g. 4.4.3) does not warn about or error the incorrect call of a nullary function?

Expand|Select|Wrap|Line Numbers
  1. void hello() {
  2. }
  3.  
  4. int main( int argc, char* argv[] ) {
  5.  int test = 1234;
  6.  hello(test);
  7.  
  8.  return 0;
  9. }
  10.  

-----
Update:
also see http://stackoverflow.com/questions/3...ith-parameters
Aug 10 '10 #1
6 2697
newb16
687 512MB
3.4.4 errors out with 'too many argument' as expected. Does your gcc {emit code that} actually calls it? What if you call function with 1 argument without argumnents?
Aug 10 '10 #2
void hello() {} and calling hello( test ) goes without error
void hello() {} and calling hello( test, test2 ) goes without error

void hello( int c ) {} and calling hello( ) goes with error "too few arguments" (as expected)

void hello( int c ) {} and calling hello( test, test2 ) goes with error "too many arguments" (as expected)

It seems a nullary function is a special case and GCC doesn't warn or error .....
Aug 10 '10 #3
newb16
687 512MB
In C ( not C++ ) it's true and empty argument list means any number of arguments.
Aug 10 '10 #4
newb16, thank you.

Two questions:
- if an empty argument list means any number of arguments, how are you supposed to access them? Directly on the stack? Are you actually supposed to access them?
- do you have any reference that this behavior is according to the standard?
Aug 10 '10 #5
newb16
687 512MB
From wiki - "This provides backward compatibility with K&R C, which lacked prototypes."
So there may be no way to use this 'feature' in standard C.
Aug 10 '10 #6
donbock
2,426 Expert 2GB
You are inadvertently using an "old-style" function definition for hello.

Do this and you will get a compiler warning on line 6:
Expand|Select|Wrap|Line Numbers
  1. void hello(void) {
  2. }
Aug 10 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John Miles | last post by:
Hi -- This is a bit of an implementation-specific problem, but I'd like to post it here to see if there's a general answer within the auspices of the language. I'm developing a high(er)-level...
2
by: bbxrider | last post by:
i'm trying to pass a form object to a function to validate the forms user input when i try to access a forms properties-like .elements there is no response from the function and no error msg, i...
4
by: nec | last post by:
Hi, I'm having trouble calling a function thats located in a iFrame from the parent. Shortly, i can't figure out the location in DOM. In IE it works fine with a simple line of...
13
by: subnet | last post by:
What does the standard say about this: #include <stdio.h> void somefunc(int a, int b, int c) { printf("%d %d %d\n", a, b, c); } int main(void) { int i = 5;
27
by: Marlene Stebbins | last post by:
I am experimenting with function pointers. Unfortunately, my C book has nothing on function pointers as function parameters. I want to pass a pointer to ff() to f() with the result that f() prints...
13
by: ukrbend | last post by:
I'm new to Javascript and to html and am trying to make the following code snippet work but it doesn't. It refuses to call the getPage() function and I always get a 404 error. I know the code is...
21
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if...
21
by: Dmitry Anikin | last post by:
I mean, it's very convenient when default parameters can be in any position, like def a_func(x = 2, y = 1, z): ... (that defaults must go last is really a C++ quirk which is needed for overload...
11
by: John Friedland | last post by:
My problem: I need to call (from C code) an arbitrary C library function, but I don't know until runtime what the function name is, how many parameters are required, and what the parameters are. I...
7
by: lovecreatesbea... | last post by:
Shoud we declare non-pointer function parameters with const keywords? int main(void){ int f(const int i); int i; f(i); return 0; }
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.