473,397 Members | 2,033 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,397 software developers and data experts.

Function prototype with default arg fails to compile

All:

I recently had to include a common header file into a straight C (.c file).
This header file contains a function prototype that has a default argument.
For example

int MyFunc(int MyArg = 10);

The compiler has no problems when I include this header file into a C++
(.cpp) source file, but croaks when I include it in a C (.c) source file.
The error(s) are as follows.

error C2143: syntax error : missing ')' before '='
error C2072: 'MyFunc' : initialization of a function

This isn't surprising since default arguments are a part of C++, not C.

My question: How can I compile this C module under C++ such that the header
file can successfully be compiled into this project?

Thanks,
Bill


Aug 29 '06 #1
2 1244
"Bill Davidson" <Ra************@newsgroup.nospamwrote in message
news:e0**************@TK2MSFTNGP05.phx.gbl...
This isn't surprising since default arguments are a part of C++, not C.
'Zactly Right.
My question: How can I compile this C module under C++ such that the
header file can successfully be compiled into this project?
The compilers accept switches to cause it to consider a file to be something
other than the default:

http://msdn.microsoft.com/library/de...c.2c_2f.Tp.asp

You can use the compiler's property pages in the IDE to add a switch there,
too.

Regards,
Will
Aug 30 '06 #2
Thanks, Will ! That's the switch I was looking for, but couldn't seem to
find.
..
Cheers,
Bill

"William DePalo [MVP VC++]" <wi***********@mvps.orgwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
"Bill Davidson" <Ra************@newsgroup.nospamwrote in message
news:e0**************@TK2MSFTNGP05.phx.gbl...
>This isn't surprising since default arguments are a part of C++, not C.

'Zactly Right.
>My question: How can I compile this C module under C++ such that the
header file can successfully be compiled into this project?

The compilers accept switches to cause it to consider a file to be
something other than the default:

http://msdn.microsoft.com/library/de...c.2c_2f.Tp.asp

You can use the compiler's property pages in the IDE to add a switch
there, too.

Regards,
Will


Aug 30 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
4
by: Joerg Toellner | last post by:
Hi Group, sorry, its again me with a dumb question. If i have a function with the optional parameter "mode" like this: void myfunc(char *blah, int mode = NULL) { if(mode == NULL)...
9
by: sam.s.kong | last post by:
Hello! I have a very basic question. a.c: <code> #include <stdio.h> main()
15
by: Bart Vandewoestyne | last post by:
I'm having a .c source file which at the top contains the line #include <math.h> In that source file, i declare a function dt which in its body uses the lgamma function. `man lgamma' on my...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
7
by: howmanymiles | last post by:
I am currently writing a program which works out student marks and outputs the passes and fails two files. I have written some code but it does seem work as no names are displayed and according to...
7
by: blangela | last post by:
I am currently taking a course and one of the example programs showed a function prototype something like: extern void func(); I asked why the "extern" was necessary. Someone in the class...
20
by: MikeC | last post by:
Folks, I've been playing with C programs for 25 years (not professionally - self-taught), and although I've used function pointers before, I've never got my head around them enough to be able to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.