News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Microsoft C question.

Started by hutch--, December 06, 2011, 02:05:47 PM

Previous topic - Next topic

hutch--



These are the first two lines of code in WinUser.h


#ifndef _WINUSER_
#define _WINUSER_


I am at a loss to explain the second line with the "#define". I am used to the format "#define this that" but the second line above only has one argument. Microsoft MSDN did not have any example like that so i am left guessing what the #define with a single argument is.

Is it just much the same as,


_WINUSER_ equ <0>

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

qWord

If you define a contants without any value, it is like:
_WINUSER_ TEXTEQU <>
FPU in a trice: SmplMath
It's that simple!

jj2007

Compare to Masm usage:
     IFDEF __UNICODE__
       echo UNICODE Build
     ELSE
       echo ASCII build
     ENDIF


I prefer
 Ifndef TheFlag
TheFlag=0
 endif

because it allows you to set TheFlag=1 before including the file, if needed:
 TheFlag=1
 Ifndef TheFlag
TheFlag=0  ; default
 endif
 if TheFlag
echo congrats, you set the flag!
 endif

clive

It's "defined" but has no value. As opposed to not existing at all. It could have a value, but it is immaterial to the test.

#ifndef _WINUSER_ // Been here already?
#define _WINUSER_ // No, mark it so we don't next time around
..
#endif

The purpose of the pairing you describe is to stop the include file's content be included a second time around, C++ gets really bent out of shape if you prototype the same stuff more than once. And some of the include files can potentially get pulled in at various places, or by the user, or in a circular fashion if you are particularly unlucky.
It could be a random act of randomness. Those happen a lot as well.

SteveAsm

C programmers use this sort of statement all the time.
Such as:

#ifndef _debug_MyApp_
#define _debug_MyApp_
...
#endif


yadayada...then...,

#ifdef _debug_MyApp_
   //some debugging routine here.
#endif


also, I will use similar when compiling the same code using different compilers or platforms that require different setups or parameters.
Such as:

//#define MingW
//#define LccWin32
//#define PowerC
#define MsVC


and un-comment the one that is currently being used.

clive

Others just use the defines the compiler provides to identify itself, and it's version

_MSC_VER
__WATCOMC__
__ICL
__TURBOC__
__GNUC__
__TASKING__
__CC_ARM
__ICC_ARM__

Which has the added benefit of not having to edit the file, or have multiple copies under management
It could be a random act of randomness. Those happen a lot as well.

hutch--

Gratsie all. If I have it right when converting this to MASM it can be,


VAR equ <anything>
; or
VAR TEXTEQU <anything or nothing>


I get the sense of it OK I think, in the MASM32 include files they all have a duplicate guard so it makes sense that C/C++ would do much the same thing.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Quote from: hutch-- on December 07, 2011, 12:28:48 AM
in the MASM32 include files they all have a duplicate guard

Exactly. Consider using the = syntax, it allows e.g.

MasmVersion=614
...
if MasmVersion ge 615
  echo You have SSE2
else
  echo No SSE2, sorry
endif

hutch--

JJ,

You may like this, at least in MASM.



    mlver MACRO
      IFIDN @Version,<614>
        % echo Your version of ML is 6.14 and you can use SSE instructions
      ENDIF
      IFIDN @Version,<615>
        % echo Your version of ML is 6.15 and you can use SSE2 instructions
      ENDIF
    ENDM

    mlver
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Almost the same but with numbers, allowing a >= comparison:
if @Version gt 614
echo You can use SSE2
endif
if @Version ge 800
echo You can use SSE3
endif
if @Version ge 900
echo You should use Jwasm, hehe
endif
tmp$ CATSTR <MyVersion=>, @Version
% echo tmp$
.err

KeepingRealBusy

Quote from: hutch-- on December 06, 2011, 02:05:47 PM


These are the first two lines of code in WinUser.h


#ifndef _WINUSER_
#define _WINUSER_


I am at a loss to explain the second line with the "#define". I am used to the format "#define this that" but the second line above only has one argument. Microsoft MSDN did not have any example like that so i am left guessing what the #define with a single argument is.

Is it just much the same as,


_WINUSER_ equ <0>



Hutch,

Same as an ML command using -D_WINUSER_, you have a defined variable with no value - supposedly to be used with "IFDEF _WINUSER_ .... ENDIF"

Dave