473,396 Members | 1,738 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.

use of #define (...) #undefine ?

84
Hello,
I'm studying a program where at some point something is defined and little bit further undefined. What could be the use of this? Is it to allocate some memory to things and then not touching them until re-defined elsewhere?

I don't know if posting the code clears the things up, but anyway it is (source cmbeasy):
Expand|Select|Wrap|Line Numbers
  1. #define CACHESPLINE(a) Spline* a; double a##X, a##Y      /* a define for the spline variables for convenience: one refernce and two caching double variables */
  2.  
  3.  
  4.  CACHESPLINE(Visibility);
  5.  CACHESPLINE(DVisibility);
  6.  CACHESPLINE(DDVisibility);
  7.  CACHESPLINE(Tau2A);
  8.  CACHESPLINE(Tau2ADot);
  9.  CACHESPLINE(Tau2ADotToA);
  10.  CACHESPLINE(Opac);
  11.  CACHESPLINE(D2Kappa);
  12.  CACHESPLINE(Expmmu);
  13.  CACHESPLINE(FreeElectronFraction);
  14.  
  15.  CACHESPLINE(Tau2Rho);
  16.  CACHESPLINE(Tau2Rho_g);
  17.  CACHESPLINE(Tau2Rho_nu);
  18.  CACHESPLINE(Tau2Rho_nuNR);
  19.  CACHESPLINE(Tau2Rho_m);
  20.  CACHESPLINE(Tau2Rho_b);
  21.  CACHESPLINE(Tau2Rho_cdm);
  22.  
  23.  
  24.  CACHESPLINE(Tau2RhoDot);
  25.  CACHESPLINE(Tau2RhoDot_m); 
  26.  CACHESPLINE(Tau2RhoDot_g);
  27.  CACHESPLINE(Tau2RhoDot_nu);
  28.  
  29.  CACHESPLINE(Tau2GRho);
  30.  CACHESPLINE(Tau2GRhoDot);
  31. (...)
  32. #undef CACHESPLINE
  33.  
Thanks in advance
May 7 '07 #1
3 5719
gpraghuram
1,275 Expert 1GB
Hi,
Basically the used after the #define CACHESPLINE will be expecting this and when it is not needed they are calling the #undef
Others acn add more info on this

Thanks
Raghuram
May 7 '07 #2
sanctus
84
But are the values stored somewhere after the undefine comand?
May 7 '07 #3
Banfa
9,065 Expert Mod 8TB
The main reason to undef a symbol is if you want to use it again later for something else.

In your example do all those code lines appear in the same file?

I technique I have seen and used is to have a header file that uses a symbol like your CACHESPLINE to define various instances of an item. Then in the C/C++ files the synbol is defined to 1 thing and the header is included then the symbol is undefined, then the symbol is defined to something else and the header is included again and the symbol is undefined again.

In this way you can define all the data required about a set of things in 1 place (the header) and then declare, define and initialise it just by defining the symbol correctly.
May 7 '07 #4

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

Similar topics

97
by: s | last post by:
Can I do this: #define MYSTRING "ABC" .. .. .. char mychar = MYSTRING; .. .. ..
18
by: Bryan Parkoff | last post by:
"#define" can only be inside the global scope before main() function. "#if" can be tested after "#define" is executed. The problem is that "#define" can't be inside main() function. I do not wish...
3
by: theotyflos | last post by:
Hi all, I have the following: /*--- SNIP ---*/ typedef struct Argument_s { char *address; int type;
2
by: Wilfried Mestdagh | last post by:
Hi, If I put a #define somewhere in a file then the compiler complains with 'cannot define/undefine after first token in file' So I plase #define in very begin of file, but then compiler say...
7
by: Nobody | last post by:
Anyone have a clean way of solving this define issue? In Windows, there are sometimes unicode functions and multibyte functions... the naming convention used is FunctionA for multibyte and...
6
by: AMP | last post by:
I have all these #define commands in a c++ file I am converting to C#. They usually have a value assigned to them: #define BSL_TXBLK 0x12 What is the c# equivalent for this. (It wont accept...
71
by: David T. Ashley | last post by:
Where is the best place to define TRUE and FALSE? Are they in any of the standard include files, ever? Do any standards apply? What I've traditionally done is something like: #ifndef...
5
by: Rocky86 | last post by:
hi people basically I am having a problem with the followinng code: $names=sizeof($temp); $report="total=$names&"; foreach($temp as $list) $report.="name".$names--."=".$list."&"; echo...
6
by: Pietro Cerutti | last post by:
Hi Group, is there a mean to undefine a function, in a similar way as you can undefine macros? For example, let's say that I need a few declarations from stdio.h but want to define my own...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.