What does #define mean when there are only 2 parts?

I know the following 3 parts #define:

#define PI 3.4

which means that it will replace PIwith 3.4.

But that means 2 parts #defineas follows:

#define something

Will it replace with somethingan empty / empty string?

Below is sample code, I was looking for a file, only a list of related lines

  D:\mariadb\storage\pbxt\src\cache_xt.cc (23 hits)  
    Line 172: #ifdef xtPublic  
    Line 173: #undef xtPublic  
    Line 188: #define xtPublic  
    Line 325: xtPublic XTIndHandlePtr xt_ind_get_handle(..)  
    Line 378: xtPublic void xt_ind_release_handle(XTIndHandlePtr..)  
    Line 516: xtPublic xtBool xt_ind_copy_on_write(XTIndReferencePtr iref)  
    Line 597: xtPublic void xt_ind_lock_handle(XTIndHandlePtr handle) 
+3
source share
5 answers

Yes, that means replacing with somethingan empty string. But now it’s important that the somethingpreprocessor recognizes that it is “defined”, therefore

#ifdef something

will pass after that #define(line 172).

In addition, it is usually used for configuration or provider-specific attributes (line 325, ...), for example

#if MSVC
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif

EXPORT void f();
// expand to '__declspec(dllexport) void f()' in MSVC
// expand to 'void f()' in other compilers
+14

, . .

+1

#define something - . .

void getValue(IN int& x, OUT int& y). #define IN and #define OUT it will not give a compiler error and anybody will get to know x is input and y is output

#ifndef __ABC_H__
#define __ABC_H__

...

#endif

, . "Abc.h"

+1

, , #define .

+1

, . , .

+1

All Articles