473,785 Members | 3,032 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

#define p

#define q p

I must admit to a most elementary confusion. I have only ever used
#define to, in point of fact, #redefine . The above is standard. Is
the following:

#define UNNAMED_OS_32_L EAN_AND_MEAN

? frank
--------
-1
Jun 7 '06
11 2412
Keith Thompson wrote:
"Joe Smith" <gr**********@n etzero.net> writes:
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org...
Frank Silvermann <in*****@invali d.net> writes:
Yeah. What does the preprocessor do with:
#define SWAP(m, n) (tmp = m, m = n, n= tmp)
?
This is a "function-like" macro. An invocation of it requires
arguments in parentheses. SWAP(foo, bar) is replaced by the
definition of SWAP, with each occurrence of m replaced by foo,
and each occurrence of n replaced by bar.

I agologize in advance for confusion with my newsreaders, the other one of
which is behaving badly despite having been killed and re-installed.
Anyways, am I right to think that if I have this macro, then I'm going to
want to have a 'tmp', 'm' and 'n' of the same type, and that this type could
be different depending on what is in scope during the SWAP?


Right. This:

SWAP(foo, bar)

is *exactly* equivalent to this:

(tmp = foo, foo = bar, bar= tmp)

so exactly the same considerations apply.

Incidentally, it's generally safer to fully parenthesize each macro
argument in a macro definition:

#define SWAP(m, n) (tmp = (m), (m) = (n), (n) = tmp)

It shouldn't matter for any reasonable invocation of SWAP(), but it's
easier to *always* use parentheses than to try to figure out when
they're not required (and force anyone reading and/or maintaining the
code to stop and think about it).
This statement is different from
#define SOMETHING
, and according to the above, the preprocessor replaces SOMETHING with
nothing. (?)
Right.

But this amnesia comes after the #IFDEF's, probably right at the end of step
4?


Yes, assuming that "step 4" means "translatio n phase 4".

Here's my usual example of preprocessor abuse:

#include <stdio.h>

#define SIX 1+5
#define NINE 8+1

int main(void)
{
printf("%d * %d = %d\n", SIX, NINE, SIX * NINE);
return 0;
}

Fun example. The fellow who was top-posting today wrote:
"Btw... nice use, of algebraic precedence (always nice to see)."
I didn't want to ruin his day and tell him that algebraists typically
work right to left and that telling left from right is the hardest thing
we do. Your example shows good form not just for a walking C
encyclopedia, but the next guy as well. frank
Jun 9 '06 #11
On Thu, 08 Jun 2006 19:00:49 GMT, Keith Thompson <ks***@mib.or g>
wrote:
Frank Silvermann <in*****@invali d.net> writes:

The direction I'm headed with this is to wonder about the types of 'm'
and 'n'. frank


They don't have types. Macro replacement just does textual
substitution (actually it works on tokens, but it's pretty much the
same thing). The preprocessor has no concept of types or expressions.


<pedantic> Preprocessor _macros_ have no concept of types, or of
expressions beyond matching/nested parentheses.

Preprocessor #if and #elif do have expressions _almost_ the same as
constant (compile-time) expressions in the language, but types limited
to the largest integer types, [u]long in C90 and [u]intmax_t in C99.

- David.Thompson1 at worldnet.att.ne t
Jun 19 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
8930
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 to create multiple functions which they look almost identical in C++ source code. The C++ compiler should be able to compile one Test() function into two almost identical functions before they are translated into the machine language object. ...
2
5594
by: Andreas | last post by:
Hi! I'm using an IplImage library from camellia.sourceforge.net, and the testbench calls a file only containing code like the one below. In cam_morphomaths_code.c the real computation is made, but I don't understand where cam_morphomaths_code.c is included and how to set what parameters to use in the testbench. How does this code execure? I don't understand a bit...
3
10584
by: theotyflos | last post by:
Hi all, I have the following: /*--- SNIP ---*/ typedef struct Argument_s { char *address; int type;
9
3095
by: pozz | last post by:
Hi all, I have the below #defines #define NUMBER1 30 #define NUMBER2 50 #define SUM (NUMBER1+NUMBER2) #define STRING1 "Byte: \x30" #define STRING2 "Byte: \x50" If I change NUMBER1 and NUMBER2 I must change STRING1 and STRING2 consequently.
34
3216
by: BQ | last post by:
Hello Is there a way to declare 'FUNCT' via a define so that if its parameter x, a constant, is greater than 35, it returns 56, if not, 20. I would like that at compile time, not at run time. So: #define FUNCT(x) x>35?56:20
17
2780
by: niraj.tiwari | last post by:
What is meaning of the following define:- #define x(argl...) x1(##argl)
71
33231
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 (TRUE) #define TRUE (1)
6
27888
by: anirbid.banerjee | last post by:
Hi, I need to write a macro which would have a lot many conditional #ifdef ... #endif blocks in it. #define _xx_macro (x) { ... \ ... \ /* some code (); */ #ifdef _SOME_STMT \ ... \ ... \
23
3922
by: anon.asdf | last post by:
Hello! In the following code-snippet, is it possible to initialize each element of arr, with STRUCT_INIT? struct mystruct { int a; char b; };
2
2301
by: badc0de | last post by:
Hello.. a header file of one of my project has macro definitions like this (for example) #define PART_A_SORT_1_LABEL_STRING1 100 #define PART_A_SORT_1_LABEL_STRING2 200 #define PART_A_SORT_1_LABEL_STRING3 300 #define PART_A_SORT_1_LABEL_STRING4 400 #define PART_A_SORT_1_LABEL_STRING5 500
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10327
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10151
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3647
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.