-
June 11th, 2014, 11:29 AM
#1
[RESOLVED] void pointer argument in a function
Hi all,
Why does the following code compile and execute without any error? I mean, the function compareid should get 2 arguments so why does the compiler not complaining, is it because of the type of arguments?
Thanks.
Code:
#include <stdio.h>
int compareid(void* info, int value); // ansi declaration
int compareid(void* info, int value)
/* Some code here */
return( foundItem == value );
}
int main( void ){
/* more code...*/
compareid;
printf("\nThis program works\n");
return(0);
}
-
June 11th, 2014, 11:41 AM
#2
Re: void pointer argument in a function
Doesn't compile for me.
1>c:\cg\cg\cg.cpp(7): error C2143: syntax error : missing ';' before 'return'
1>c:\cg\cg\cg.cpp(8): error C2059: syntax error : '}'
1>c:\cg\cg\cg.cpp(8): error C2143: syntax error : missing ';' before '}'
1>c:\cg\cg\cg.cpp(10): error C2143: syntax error : missing ';' before '{'
1>c:\cg\cg\cg.cpp(10): error C2447: '{' : missing function header (old-style formal list?)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-
June 11th, 2014, 12:00 PM
#3
Re: void pointer argument in a function
Originally Posted by StephaneLeFou
Hi all,
Why does the following code compile and execute without any error? I mean, the function compareid should get 2 arguments so why does the compiler not complaining, is it because of the type of arguments?
Originally Posted by GCDEF
Doesn't compile for me.
1>c:\cg\cg\cg.cpp(7): error C2143: syntax error : missing ';' before 'return'
1>c:\cg\cg\cg.cpp(8): error C2059: syntax error : '}'
1>c:\cg\cg\cg.cpp(8): error C2143: syntax error : missing ';' before '}'
1>c:\cg\cg\cg.cpp(10): error C2143: syntax error : missing ';' before '{'
1>c:\cg\cg\cg.cpp(10): error C2447: '{' : missing function header (old-style formal list?)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I had the same result as GCDEF.
Dear StephaneLeFou,
please, next time check if your pseudo/code does compile before posting it to Forum!
Victor Nijegorodov
-
June 11th, 2014, 12:02 PM
#4
Re: void pointer argument in a function
Are you compiling as c or as c++?
Where is foundItem defined?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 11th, 2014, 12:10 PM
#5
Re: void pointer argument in a function
If compiled as c as opposed to c++, the program below compiles and executes.
Code:
#include <stdio.h>
int compareid(void* info, int value); // ansi declaration
int compareid(void* info, int value)
{
int foundItem = 1;
/* Some code here */
return( foundItem == value );
}
int main( void ){
/* more code...*/
compareid;
printf("\nThis program works\n");
return(0);
}
There is a warning 'expression evaluates to a function which is missing an argument list'.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
June 16th, 2014, 08:00 AM
#6
Re: [RESOLVED] void pointer argument in a function
Originally Posted by StephaneLeFou
This is not a function call. it is just an identifier, which ends up doing nothing in the compiled code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|