473,396 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Purpose of code '#define'

HI All.
Im new in c++. some wher i saw the code
Expand|Select|Wrap|Line Numbers
  1. #define DECLAREDLL
  2.  
  3. class DECLAREDLL myclass
  4. {
  5. };
  6.  
why DECLAREDLL before class name?
can any body solve my doubt?
THANK U.
Sep 4 '07 #1
5 2854
gpraghuram
1,275 Expert 1GB
HI All.
Im new in c++. some wher i saw the code

#define DECLAREDLL

class DECLAREDLL myclass
{
};

why DECLAREDLL before class name?
can any body solve my doubt?
THANK U.
I cant figure out why they have used this but the DECLAREDLL will be nothing when the proprocessing happens and the declartion changes to class myclass{};

Raghuram
Sep 4 '07 #2
sicarie
4,677 Expert Mod 4TB
HI All.
Im new in c++. some wher i saw the code

#define DECLAREDLL

class DECLAREDLL myclass
{
};

why DECLAREDLL before class name?
can any body solve my doubt?
THANK U.
That is a declaratory statement. I have seen them usually be
Expand|Select|Wrap|Line Numbers
  1. #ifndef DECLAREDLL
  2. #define DECLAREDLL
  3. class....
  4.  
This means "if not defined" and then it will search for another declaration of whatever is in the space of 'DECLAREDLL', then it will define it for the project. I'm not sure of the scope of this - but I believe it will be for the namespace. The code you posted will not check for another instance of 'declaredll' so another version might be overwritten.

PS - In the future, please use code tags. Thanks!
Sep 4 '07 #3
kreagan
153 100+
HI All.
Im new in c++. some wher i saw the code
Expand|Select|Wrap|Line Numbers
  1. #define DECLAREDLL
  2.  
  3. class DECLAREDLL myclass
  4. {
  5. };
  6.  
why DECLAREDLL before class name?
can any body solve my doubt?
THANK U.
I am also new to c/c++, but have worked with a couple of instances where you need to define the file. Usually you will use:

Expand|Select|Wrap|Line Numbers
  1. #ifndefine DECLAREDLL
  2. #define DECLAREDLL
As someone said in this post, you define DECLAREDLL if DECLAREDLL is not defined. What this does, if this file is not loaded in memory, the compiler will do so. If there is an instance where this file is loaded in memory, the compiler will access the file that has been loaded instead of loading the code again. (At least that's how it has been told to me.

Another use can be when you create DLLs.

Expand|Select|Wrap|Line Numbers
  1. #ifdef DECLAREDLL
  2.     #define    DECLAREDLL_DLL __export __cdecl
  3. #else
  4.     #define DECLAREDLL_DLL __import __cdecl
  5. #endif
which basically states that if DECLAREDLL is define (see above), insert __export __cdecl where DECLAREDLL_DLL typed, otherwise, use __import __cdecl.

Hope that make sense.
Good luck.
Sep 4 '07 #4
dmjpro
2,476 2GB
All these are for Conditional Compilation.
You know it?

Kind regards,
Dmjpro.
Sep 4 '07 #5
sicarie
4,677 Expert Mod 4TB
Found this today, it has another explanation of that in there.
Sep 5 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Maarten van Reeuwijk | last post by:
Hi group, I need to parse various text files in python. I was wondering if there was a general purpose tokenizer available. I know about split(), but this (otherwise very handy method does not...
8
by: chris | last post by:
I tried to post this to comp.std.c++ some time ago, but for some reason I aren't getting any automatic confirmation. I thought I would therefore post it here. Some time ago I submitted what is...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
8
by: Andante.in.Blue | last post by:
Hello, I have just inherited a legacy Access 97 database. While going through it, I noticed something strange... its Relationships window (the one accessed by Tools --> Relationships) is almost...
18
by: Razvan | last post by:
Hi! What is the purpose of such a function ? int function(void)
27
by: jm | last post by:
I am having trouble understanding the purposes of an interface, even though the concept of interfaces is around me all the time (user interface, for example). I'm just not understanding software...
12
by: djhong | last post by:
Following is a snippet of a header file. Here, #define are inside struct evConn{} Any advantage of putting them inside struct block? Looks like there is no diff in scoping of each...
2
by: parag_paul | last post by:
Isnt is so that whenever the compiler reads an #def it will replace it with letter by letter on the place is see the macro, so what is the purpose of keeping #defs inside a structure, struct...
37
by: Phlip | last post by:
1230987za wrote: Kanze is a classically-trained "unit tester". In some circles "unit" is a QA concept - specifically, if a test fails, you only need to inspect one unit. So "units" are...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.