LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 09-03-2005, 04:37 PM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,028

Rep: Reputation: 45
Problem with c header file


Hi i have two files one .c and one header .h
in the header file i have used a define statement
#define SIZE 5
I have noticed that the SIZE is not visible in the c file.. Do u know why i cant define something in a header file so as to be visible to the c file also?
 
Old 09-03-2005, 04:53 PM   #2
gruby12
LQ Newbie
 
Registered: Aug 2005
Location: Poland
Distribution: SUSE 10.1, Mandriva 2008.1
Posts: 26

Rep: Reputation: 15
Do you have #include "header.h" directive in your .c file?
 
Old 09-03-2005, 05:56 PM   #3
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,028

Original Poster
Rep: Reputation: 45
Yes i have
 
Old 09-03-2005, 09:00 PM   #4
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
Whats the error message you're getting, and what line of code is causing the problem?

I imagine you're doing something like this:

type identifier[SIZE];

??

You should be more specific than just saying something doesn't work...
 
Old 09-03-2005, 09:06 PM   #5
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,858
Blog Entries: 1

Rep: Reputation: Disabled
1. if you "#define SIZE 5" in header.h, and if you #include "header.h" in your .c file, the the .c file should have SIZE.

For troubleshooting, the "#error" directive is your friend.

Make sure your "-I" (include header) compile switches are set correctly (you might even need "-I." to include headers in the current directory. Make sure there are no "#ifdef's" that are "filtering out" your #define.

And finally, edit "header.h" and put "#error SOME MESSAGE" right after "#define SIZE". Recompile your C program. It should die at the "#error" line. Adjust your "-I" compile switch, and move the #error around in your .h file, until it does die. At that point: voila! You've found the problem.

2. With regard to your oid initialization question: please declare the oid array[] "extern" in the header, then define it (and initialize the data) in one or another C/C++ file.

'Hope that helps .. PSM
 
  


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
header file problems in g++ crash_override_me Programming 5 10-07-2005 01:28 AM
header file extraction ? (.hdr) t3gah Linux - Software 1 03-21-2005 03:57 AM
Create header file for existing .c file hk_michael Programming 5 02-25-2005 05:26 PM
header file location ..mach.h .. pashupathinath Programming 1 10-21-2004 06:27 PM
Compiling a header file with gcc Squall Linux - Software 2 04-07-2004 05:16 AM


All times are GMT -5. The time now is 02:49 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