LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-28-2012, 12:14 AM   #1
Navjot Arora
LQ Newbie
 
Registered: Apr 2012
Location: Bangalore
Distribution: J ARORA
Posts: 22

Rep: Reputation: Disabled
expected constructor, destructor, or type conversion before â;â token


Hi All,

I am facing an error "expected constructor, destructor, or type conversion before â;â token"in the below code:

#ifdef SUN
extern "C" gethostname(char*, int);
#endif

Any help will be appreciated
 
Old 06-28-2012, 12:15 AM   #2
Navjot Arora
LQ Newbie
 
Registered: Apr 2012
Location: Bangalore
Distribution: J ARORA
Posts: 22

Original Poster
Rep: Reputation: Disabled
Just to mention that this error came in g++ in Linux
 
Old 06-28-2012, 12:59 AM   #3
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Code:
#ifdef SUN
extern "C" {
    int gethostname(char *, size_t);
}
#endif
 
Old 06-28-2012, 02:53 AM   #4
Navjot Arora
LQ Newbie
 
Registered: Apr 2012
Location: Bangalore
Distribution: J ARORA
Posts: 22

Original Poster
Rep: Reputation: Disabled
Hi Nominal,

Thanks a lot, it worked but here my question is how it perfectly compiled in solaris using CC Compiler that too without using curly braces
 
Old 06-28-2012, 03:08 AM   #5
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Quote:
Originally Posted by Navjot Arora View Post
how it perfectly compiled in solaris using CC Compiler that too without using curly braces
The braces were not the issue, although I do recommend always using them, it makes it easier for humans to read.
Code:
#ifdef SUN
extern "C" int gethostname(char *, size_t);
#endif
The reason it worked in Solaris is because there the compiler was so old it still treated a C function prototype without explicit return type as returning int. (I think. I didn't actually check.)

Just because it worked in Solaris does not mean it should work in general. We have standards for that, and Solaris is not exactly known for following standards.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
expected initializer before â??<â?? token grob115 Programming 5 12-12-2011 07:56 AM
Compile error: expected constructor, destructor, or type conversion before class ilnli Programming 8 07-12-2011 09:32 PM
expected unqualified-id before ‘{’ token in C knobby67 Programming 3 04-25-2009 04:11 AM
c++ template function, expected constructor, destructor, or type conversion parv Programming 18 01-25-2008 02:54 PM
Does derivated class inherit base class destructor (constructor)? kornerr Programming 2 08-23-2006 08:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:12 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration