LinuxQuestions.org
Help answer threads with 0 replies.
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
 
LinkBack Search this Thread
Old 04-27-2004, 09:00 PM   #1
vtluu
LQ Newbie
 
Registered: Mar 2004
Location: Vietnam
Posts: 9

Rep: Reputation: 0
extern "C" and static data type problem with g++


In RH Linux 9, when compiling my C++ program with lines as below:

extern "C" struct s {int x;};
static enum e{A=0, B, C};

g++ said:

storage class specified for field `x'
`static' can only be specified for objects and functions

Is this just the implementation of g++? That means I can't use static and extern "C" for those lines of code?

Actually, those lines of code were compiled OK with Sun CC compiler (Sun ONE Studio 8 in Solaris 8). I wonder if C++ standard allows such declarations but g++ didn't implement them or such declarations are just an extension of Sun CC compiler

Another question: with GNU g++/gcc compiler and its C++ library, can I use both traditional C++ lib (e.g., classic iostream) and standard C++ lib (e.g., standard iostream) in my C++ program. Are the both libraries implemented in glibstdc++?

Any help will be appreciated.

Luu Vo.
 
Old 04-27-2004, 09:09 PM   #2
kooch
Member
 
Registered: Mar 2004
Location: Upstate NY
Distribution: Slackware/YDL
Posts: 77

Rep: Reputation: 15
Quote:
extern "C" ...
I wasn't aware that was allowed by _any_ C++ compiler. What does it mean?
 
Old 04-28-2004, 05:10 AM   #3
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
enum is a type you cannot use the static qualifier, so use this instead:

Code:
enum e {A=0, B, C};
static e my_val = B;
Also I think you want to change the extern bit to:

Code:
extern "C" 
{
struct s {int i;};
};
I would have to check this one though, don't have any references to hand ... basically I think you only want C language linkage.
You have not created an actual value or function so you can't give it extern linkage that your syntax tries to, but I may stand corrected.

HTH

Last edited by dakensta; 04-28-2004 at 05:12 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Ooo BASIC Macro problem: "connot coerce argument type..." tredegar Linux - Software 0 08-14-2005 10:00 AM
web surfing problem... i have to type in "http://" fatrandy13 Linux - Software 8 05-23-2005 02:48 AM
extern "C" and static data type problem with g++ vtluu Red Hat 1 05-21-2004 10:45 AM
Hi dakensta- one more problem- "Not an aggregate type" ashwinipahuja Programming 3 04-30-2004 06:42 AM
<input type="button" disabled="true" > does not work in ns4.7 or 4.9 cybercop12us Programming 2 11-29-2002 08:31 AM


All times are GMT -5. The time now is 05:42 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration