Error No Direct Declarator Preceding
Dangerous By Nicholas Solter on Aug 09, 2007 A co-worker recently asked me to look at an interesting C++ compilation problem. The constructor for one of her classes refused to compile until she simply changed one of the parameter names! Why should the parameter name matter?
Here's a much-simplified version of the class, with a trivial main(), removing proprietary information (this code isn't yet open-source). #include #include #include class myclass { public: myclass(char \*s_net); }; myclass::myclass(char \*s_net) { // do stuff } int main() { // do stuff } The Sun Studio 10 compiler gives the following errors when attempting to compile the translation unit: "test.cc", line 7: Error: No direct declarator preceding "(". "test.cc", line 10: Error: myclass is not a static data member. "test.cc", line 10: Error: Badly formed expression. Changing the name of the only parameter to the myclass constructor to something else like net allows the code to compile with no errors. What's going on? It turns out that s_net is defined in netinet/in.h as follows #define s_net _S_un._S_un_b.s_b1 /\* OBSOLETE: network \*/ So when the preprocessor makes its substitutions prior to the actual compilation, the symbol s_net is replaced with something like _S_un._S_un_b.s_b1. (There are actually a few more substitutions, as we'll see momentarily). We can see this ourselves by using the -P option to CC to run the test program through just the preprocessor. This gives, in part: class myclass { public : myclass ( char \* S_un . S_un_b . s_b1 ) ; } ; myclass :: myclass ( char \* S_un . S_un_b . s_b1 ) { } That obviously won't compile! This example demonstrates two problems. The first is the use of globals, specifically #defines. Who would expect a generic symbol like s_net to be #defined in a standard header file? It would be bad enough if it were simply a global variable, but that at least would probably not have caused a problem in this case, because the use of s_net in the constructor would hide the global s_net. However, the preprocessor actually search/replaces the #define term so that the compiler never gets a chance to see s_net as the parameter name in the constructor. The second problem is that the preprocessor does this substitution and other modifications such that the code for which the compiler is giving a warning is not the code that you see when you look at your source file. This can make debugging difficult. Moral of the story: Use the preprocessor judiciously! Category: C++ Tags: #define c++ debugging declarator direct no precedingfor Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Ask a Question Ask for Help Receive Real-Time Help Create a Freelance Project Hire for a Full Time Job Ways to Get Help Expand Search Submit Close Search Login Join Today Products BackProducts Gigs Live Careers Vendor Services Groups Website Testing Store Headlines Experts Exchange https://blogs.oracle.com/nsolter/entry/one_more_reason_the_c > Questions > Error in system header file... Want to Advertise Here? Solved Error in system header file... Posted on 2001-10-05 C++ 1 Verified Solution 9 Comments 795 Views Last Modified: 2010-09-29 When I'm trying to compile a program getting the following error.. Not able to figure https://www.experts-exchange.com/questions/20191075/Error-in-system-header-file.html out whatz causing this... "/opt/SUNWspro/WS6U1/include/CC/Cstd/./limits", line 146: Warning: Too few arguments in macro min. "/opt/SUNWspro/WS6U1/include/CC/Cstd/./limits", line 146: Error: No direct declarator preceding "(". "/opt/SUNWspro/WS6U1/include/CC/Cstd/./limits", line 146: Error: Use ";" to terminate declarations. "/opt/SUNWspro/WS6U1/include/CC/Cstd/./limits", line 147: Error: Use ";" to terminate declarations. "/opt/SUNWspro/WS6U1/include/CC/Cstd/./limits", line 147: Warning: Too few arguments in macro max. "/opt/SUNWspro/WS6U1/include/CC/Cstd/./limits", line 147: Error: No direct declarator preceding "(". "/opt/SUNWspro/WS6U1/include/CC/Cstd/./limits", line 147: Error: Use ";" to terminate declarations. "/opt/SUNWspro/WS6U1/include/CC/Cstd/./limits", line 149: Error: Use ";" to terminate declarations. I'm not including limits anywhere in my program. Could anyone guide me thru what could be the problem Best Regards, Lalitha 0 Question by:alalitha Facebook Twitter LinkedIn Google LVL 30 Best Solution byAxter I see that you're using
> Visual C++ Question 0 Sign in to vote #ifndef _MasterRobot #define _MasterRobot #include
Date: Tue, 27 Jun 2006 16:31:41 -0500 Has anyone tried to compile the resiprocate SIP stack with Sun Forte 6 u2 compiler? I am getting compile errors. Any help is appreciated. rajesh@constellation:/home/rajesh/3rdparty/sip/resiprocate-0.9.0-5019 ]make Compressing paths Making all in resiprocate make all-recursive Making all in . source='external/HttpGetMessage.cxx' object='HttpGetMessage.lo' libtool=yes \ DEPDIR=.deps depmode=none /bin/bash ../depcomp \ /bin/bash ../libtool --tag=CXX --mode=compile --tag=CXX /vox/tools/Forte_6u2/SUNWspro/bin/CC -DHAVE_CONFIG_H -I. -I. -I. -I.. -I.. -I/usr/include -I/usr/local/ssl/include -I/home/rajesh/3rdparty/sip/resiprocate-0.9.0-5019/contrib/ares -I/usr/kerberos/include -g -c -o HttpGetMessage.lo `test -f 'external/HttpGetMessage.cxx' || echo './'`external/HttpGetMessage.cxx /vox/tools/Forte_6u2/SUNWspro/bin/CC -DHAVE_CONFIG_H -I. -I. -I. -I.. -I.. -I/usr/include -I/usr/local/ssl/include -I/home/rajesh/3rdparty/sip/resiprocate-0.9.0-5019/contrib/ares -I/usr/kerberos/include -g -c external/HttpGetMessage.cxx -KPIC -DPIC -o .libs/HttpGetMessage.o "../resiprocate/os/Data.hxx", line 27: Error: "}" expected instead of ";". "../resiprocate/os/Data.hxx", line 31: Error: No direct declarator preceding "(". "../resiprocate/os/Data.hxx", line 32: Error: No direct declarator preceding "(". "../resiprocate/os/Data.hxx", line 33: Error: No direct declarator preceding "(". "../resiprocate/os/Data.hxx", line 34: Error: No direct declarator preceding "(". "../resiprocate/os/Data.hxx", line 35: Error: No direct declarator preceding "(". "../resiprocate/os/Data.hxx", line 36: Error: No direct declarator preceding "(". "../resiprocate/os/Data.hxx", line 37: Error: "explicit" is not allowed here. "../resiprocate/os/Data.hxx", line 37: Error: No direct declarator preceding "(". "../resiprocate/os/Data.hxx", line 38: Error: "explicit" is not allowed here. "../resiprocate/os/Data.hxx", line 38: Error: No direct declarator preceding "(". "../resiprocate/os/Data.hxx", line 39: Error: "explicit" is not allowed here. "../resiprocate/os/Data.hxx", line 39: Error: No direct declarator preceding "(". "../res