Author Topic: Preprocessor/Macro Constant  (Read 874 times)

ragdog

  • Member
  • ****
  • Posts: 610
Preprocessor/Macro Constant
« on: February 28, 2018, 05:45:01 AM »
Hello

I have a question to use a one constant string in Asm and RC files?
In Cpp can i use a include like this

Constant.h
Code: [Select]
#define ConstString "abcd"
Rc file
Code: [Select]
#include "Constant.h"

some code ConstString

In C/Cpp file to

Code: [Select]
#include "Constant.h"

int main(int argc, char* argv[])
{
      printf("My const string is: %s " ConstString "\n");

Is it possible to write a macro to convert the #define

 #define   ConstString "abcd" 

to

ConstString db "abcd",0

and use it in Masm code?

I know #define give error by compile but is there a solution?

Regards,
« Last Edit: February 28, 2018, 07:23:03 AM by ragdog »

HSE

  • Member
  • *****
  • Posts: 1004
  • <AMD>< 7-32>
Re: Preprocessor/Macro Constant
« Reply #1 on: February 28, 2018, 10:58:25 AM »
Hi Ragdog!
I think You can replace #define with STRING using some editor, like RadAsm. But you have to add a coma manually after string's name.

jj2007

  • Member
  • *****
  • Posts: 9401
  • Assembler is fun ;-)
    • MasmBasic
Re: Preprocessor/Macro Constant
« Reply #2 on: February 28, 2018, 01:21:31 PM »
Code: [Select]
include \masm32\include\masm32rt.inc

MyData equ <"Hello World">

.data
HelloW$ db MyData, 0

.code
start:
  MsgBox 0, offset HelloW$, "That was easy!!", MB_OK
  exit

end start

ragdog

  • Member
  • ****
  • Posts: 610
Re: Preprocessor/Macro Constant
« Reply #3 on: March 02, 2018, 08:15:23 AM »
Hello

@HSE yes i know i can use a editor to replace but this is not my goal
@Jochen too

I ask it is possible to use a macro to change it.

Thanks you both for reply

Regards,

sinsi

  • Member
  • *****
  • Posts: 1142
Re: Preprocessor/Macro Constant
« Reply #4 on: March 02, 2018, 09:34:39 AM »
The macro itself is fairly straightforward but masm chokes if you call it #define
Doesn't seem to like the # character.
I can walk on water but stagger on beer bourbon.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6277
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Preprocessor/Macro Constant
« Reply #5 on: March 03, 2018, 04:55:01 AM »
I would be inclined to think that,

#define   ConstString "abcd"

would become

ConstString equ <abcd>

  or

ConstString equ "abcd"


Without looking it up, perhaps a TEXTEQU.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin: