LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-11-2008, 01:10 PM   #1
Spirals
LQ Newbie
 
Registered: Jun 2006
Posts: 29

Rep: Reputation: 15
C declaration problem for a "typedef struct".


I have the following in a header file:

h file (lines numbers from vi, not in the file.)

56
57 typedef struct shm_information {
58 struct shm_information *next; /* pointer to the next information */
59 struct shm_information *prev; /* pointer to the previous information */
60 char used; /* this is for bootstrapping a new image */
61 char *start; /* start of a free spot */
62 int length; /* length of the free spot */
63
64 } SHM_INFORMATION, *SHM_INFOPTR;
65
66
67
68 #define SHM_INFO_SIZE (sizeof (struct shm_information))

As far as I can see this is almost identical to the example in

K&R Whitebook (page 140).

gcc compiler on etch [gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21) ] throws the following error messages:


gcc -c -I/home/spirals/Desktop/work/dpms/sys/include -I -L/home/spirals/Desktop/work/dpms/work/testscrobj -L/usr/lib /home/spirals/Desktop/work/dpms/work/testscrobj/shm_attach.c
In file included from /home/spirals/Desktop/work/dpms/work/testscrobj/shm_attach.c:23:
/home/spirals/Desktop/work/dpms/sys/include/dpms_shm.h:57: error: redefinition of ‘struct shm_information’
/home/spirals/Desktop/work/dpms/sys/include/dpms_shm.h:64: error: redefinition of typedef ‘SHM_INFORMATION’
/home/spirals/Desktop/work/dpms/sys/include/dpms_shm.h:64: error: previous declaration of ‘SHM_INFORMATION’ was here
/home/spirals/Desktop/work/dpms/sys/include/dpms_shm.h:64: error: redefinition of typedef ‘SHM_INFOPTR’
/home/spirals/Desktop/work/dpms/sys/include/dpms_shm.h:64: error: previous declaration of ‘SHM_INFOPTR’ was here
make: [shm_attach] Error 1 (ignored)
testrig done


Any suggestions. This code compiled clean on SCO? (around 1990) and later on Solaris 8 (in each case with the native compiler) , so I am at a loss why gcc is acting up!

I also did a grep for shm_information and SHM_INFORMATION nothing found.
 
Old 03-11-2008, 01:17 PM   #2
JudyL
LQ Newbie
 
Registered: Aug 2007
Location: Florida, USA
Distribution: Ubuntu
Posts: 29

Rep: Reputation: 15
Sounds like your header file is getting included twice. Do you have header guards in place (those things at the very top of the header like #ifndef MYHEADERNAME_H #define MYHEADERNAME_H and a corresponding #endif at the very bottom)?

Judy
 
Old 03-16-2008, 12:23 PM   #3
Spirals
LQ Newbie
 
Registered: Jun 2006
Posts: 29

Original Poster
Rep: Reputation: 15
Thank you, problem solved.

Thank you for your reply, there are no header guards in these files. When I wrote it back in 1990 (yes that long ago) it worked fine. It is real K&R code. Unfortunately gcc is not ( correct me if i am wrong) a K&R complaint compiler, so it breaks my stuff. In trying to get it running I but this bug in, addled brain. I am adding the guards having been caught out and then I am now onto next problem [lot of shared memory manipulation]. very many thanks.:):):):study:
 
Old 03-17-2008, 07:52 AM   #4
JudyL
LQ Newbie
 
Registered: Aug 2007
Location: Florida, USA
Distribution: Ubuntu
Posts: 29

Rep: Reputation: 15
Quote:
Originally Posted by Spirals View Post
Unfortunately gcc is not ( correct me if i am wrong) a K&R complaint compiler, so it breaks my stuff.
I'm not sure you can declare K&R to be a standard that a compiler must meet. The issue is how the compiler handles a second declaration that identically matches a previous declaration and I don't have the C spec handy to check what it says about that issue to know whether gcc is compliant or not. Did K&R even address how a compiler should handle that case?

Judy
 
  


Reply

Tags
struct



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
Extern "c" declaration for a function is giving error. manas_sem Programming 3 06-28-2007 12:15 PM
typedef a union as a struct? KasperLotus Programming 3 03-09-2007 01:10 PM
how to get rid of "warning : implicit declaration of function 'getpid' " ? diodio Linux - Newbie 6 02-01-2006 02:47 PM
"Multiple declaration for mbstate_t" murugesan Solaris / OpenSolaris 2 06-03-2005 05:38 AM
Where is "struct file" defined ? Not in fs.h !? bjchip Linux - General 0 05-30-2004 05:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:46 PM.

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