LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-10-2003, 02:07 PM   #1
Jo_Nak
LQ Newbie
 
Registered: Jun 2003
Posts: 20

Rep: Reputation: 0
using #define


Hi,

this is a simple question, but to which I couldn't find an answer. In a header file, if '#define' is used this way for example:

struct video
{
int ...;
cahr...;

#define VCTX 1

int...;
}

Is VCTX gonna be available in .c file as a global variable or it can only be used inside this structure?

Thanx
 
Old 06-10-2003, 02:59 PM   #2
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
# directives such as define are processed before the code reaches the compiler. VCTX can be used anyehere after its been #defined. it seems quite odd to find it in the middle of a structure definition though.
 
Old 06-10-2003, 05:17 PM   #3
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
yes #define is a preprocessor directive, just before compiling the preprocessor scans your files and replaces any VCTX with the value 1. It's just one form of a macro (often also called a symbol constant definition).
 
Old 06-11-2003, 01:37 PM   #4
croakofonix
LQ Newbie
 
Registered: May 2003
Location: Melbourne, Victoria, Australia
Distribution: RH9.0, Fedora Core 1, Fedora Core 2
Posts: 19

Rep: Reputation: 0
#define is a preprocessor statement. Also the golden rule in C is "Define Before Usage". So i think that the replacement will only be done for the lines that occur after the #define directive.
 
Old 06-11-2003, 01:46 PM   #5
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Yes that's why you usually find #defines at the very top, otherwise the compiler will bitch if it finds something not previously defined.
 
  


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
Best way to define variables? Yig Linux - Software 3 08-24-2005 05:09 PM
C++ question #define ... Bluesuperman Programming 4 02-01-2005 09:49 AM
define jhon Linux - Networking 2 08-30-2004 07:42 PM
question on #define h/w Programming 7 12-03-2003 05:14 PM
define main linuxanswer Programming 8 11-05-2003 02:02 PM

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

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