Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / August 2006

Tip: Looking for answers? Try searching our database.

Function prototype with default arg fails to compile

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill Davidson - 30 Aug 2006 00:37 GMT
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
William DePalo [MVP VC++] - 30 Aug 2006 02:26 GMT
> 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/default.asp?url=/library/en-us/vccore/html/_co
re_.2f.Tc.2c_2f.Tp.asp


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

Regards,
Will
Bill Davidson - 30 Aug 2006 15:34 GMT
Thanks, Will !  That's the switch I was looking for, but couldn't seem to
find.
.
Cheers,
Bill

>> This isn't surprising since default arguments are a part of C++, not C.
>
[quoted text clipped - 13 lines]
> Regards,
> Will

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.