The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: ToutEnMasm on June 27, 2005, 12:45:57 PM

Title: A macro that return a number usable by a constant
Post by: ToutEnMasm on June 27, 2005, 12:45:57 PM
Hello,
Translating the headers of the SDK , I found a problem
#define L_MAX_URL_LENGTH    (2048 + 32 + sizeof("://"))

Beginning of the translate is easy:

L_MAX_URL_LENGTH equ  (2048 + 32 + Its hard)

In a macro(SIZE)     i = 0    ,later,      EXITM %i    return the number but .......

L_MAX_URL_LENGTH equ  (2048 + 32 + SIZE("://")) failed

I try SIZESTR ,I try <%i>,i,<i> but no more result  , Is it possible ?.That seem work only for an another macro.

The error occured when         Variable dd L_MAX_URL_LENGTH

                                          ToutEnMasm

                                   





Title: Re: A macro that return a number usable by a constant
Post by: Jeff on June 27, 2005, 02:17:08 PM
since that is c, i believe a string, :// would be 4 bytes right? (including null terminator)  ;)

2048 + 32 + 4

it might be a good idea to evaluate the expression rather than leaving it as is.  i could be wrong.
Title: Re: A macro that return a number usable by a constant
Post by: gfalen on June 27, 2005, 02:51:14 PM
@SizeStr("://")
Title: Re: A macro that return a number usable by a constant
Post by: Jeff on June 27, 2005, 03:19:43 PM
the problem with that is that it takes the entire literal string's size.  that means, it includes the quotes.  what's worse is that it still doesnt account for the null terminator (as used in c).  tout may be more interested in the best resemblence to c.   ;)
Title: Re: A macro that return a number usable by a constant
Post by: MazeGen on June 28, 2005, 12:26:49 PM
Quote from: Jeff on June 27, 2005, 03:19:43 PM
the problem with that is that it takes the entire literal string's size.  that means, it includes the quotes.

@SizeStr(://)

or

@SizeStr(<://>)
Title: Re: A macro that return a number usable by a constant
Post by: ToutEnMasm on June 28, 2005, 01:08:16 PM
Hello,
I have made a lot of test and that is the result
#define AL_MAX_URL_LENGTH    (2048 + 32 + sizeof("://")) =2084
AL_MAX_URL_LENGTH  equ  (2048 + 32 + @SizeStr("://")) = 2085

to resume it      in c  sizeof("://") =  size of  :// + zero =4
                   in asm  @SizeStr("://") = size of "://"  = 5

I have also made a macro that can be of interest:
The syntax is  mov edx,SIZECHAINE ((I am a string))     ;note the double (())
It return the lenght of the entire string , except if there is spaces at the end,they are troncated

Thanks for the help

                                   ToutEnMasm

             
                     SIZECHAINE MACRO chaine:REQ
      local nombre
      .const
      nombre equ @SizeStr chaine
      .code
      mov eax,nombre
      EXITM <eax>
        ENDM
Title: Re: A macro that return a number usable by a constant
Post by: MazeGen on June 28, 2005, 01:22:11 PM
ToutEnMasm,
your SIZECHAINE macro is unnecessary. You can always use

mov edx, @SizeStr (Iamastring)

mov edx, @SizeStr (<I am a string>)