How to add namespace to macro function?

I

Immortal Nephi

Do you have a better way to add namespace to the macro function? I
researched do while statement. I found out that do while statement
treats like a real function in assertion source code.

#define MhiddenFunction() \
do \
{ \
( void ) sizeof( 0 ); \
\
__pragma( warning( push ) ); \
__pragma( warning( disable: 4127 ) ); \
} \
while( false ); \
__pragma( warning( pop ) )

If I add namespace name, then C++ Compiler will fail to compile
because the statement looks like

::group::do
{
….
} while( false );
 
I

Ian Collins

Do you have a better way to add namespace to the macro function?

What is a "macro function"? Macros are simple text substitutions, as
such they have file level scope and can't be wrapped in a namespace.
I researched do while statement. I found out that do while statement
treats like a real function in assertion source code.

#define MhiddenFunction() \
do \
{ \
( void ) sizeof( 0 ); \
\
__pragma( warning( push ) ); \
__pragma( warning( disable: 4127 ) ); \
} \
while( false ); \
__pragma( warning( pop ) )

If I add namespace name, then C++ Compiler will fail to compile
because the statement looks like

::group::do
{
….
} while( false );

Simple solution - don't use function like macros, they are useful in C,
but can be replaced with inline function (templates) in C++.
 
I

Immortal Nephi

What is a "macro function"?  Macros are simple text substitutions, as
such they have file level scope and can't be wrapped in a namespace.









Simple solution - don't use function like macros, they are useful in C,
but can be replaced with inline function (templates) in C++.

Well, you always write inline function in C++ source code before you
can define to create macro function. Like this…

inline void function() {} // C++ inline function

#ifdef MACRO_NAME

#define MACRO_FUNC() \
function()
#else
#define MACRO_FUNC() (( void ) 0 )
#end if

int main()
{
MACRO_FUNC();
Return 0;
}

I agree with you that macro function cannot be wrapped, but they are
always in file scope.
I wish to wrap macro functions in C++.
 
T

tonydee

        Well, you always write inline function in C++ source code before you
can define to create macro function.  Like this…

inline void function() {} // C++ inline function

#ifdef MACRO_NAME

#define MACRO_FUNC() \
        function()
#else
#define MACRO_FUNC() (( void ) 0 )
#end if

int main()
{
        MACRO_FUNC();
        Return 0;

}

        I agree with you that macro function cannot be wrapped, but they are
always in file scope.
        I wish to wrap macro functions in C++.

I'm having a bit of trouble understanding everything you're driving
at. A few thoughts though:

- it makes no difference whether the functions (or variables etc)
mentioned in the expansion of a macro are above or below the macro
definitions, but they do need to be above the expansions (unless
further deferred e.g. as part of uninstantiated templates).

- you just can not put namespaces on macros. Wanting to won't make it
happen.

Cheers,
Tony
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top