[comp.binaries.ibm.pc.d] Q: MSC & Macro substitutions

bkahn@spud.webo.dg.com (Bruce Kahn) (12/07/90)

  I may be dense but I cant seem to figure out the use of #defines w/macros
and auto substitution of parameters.  I have some Uni* code Im porting (indent
actually) that uses a statement :

#define check_size(name) \
        if (e_/**/name >= l_/**/name) { \
            register nsize = l_/**/name-s_/**/name+400; \
            name/**/buf = (char *) realloc(name/**/buf, nsize); \
            e_/**/name = name/**/buf + (e_/**/name-s_/**/name) + 1; \
            l_/**/name = name/**/buf + nsize - 5; \
            s_/**/name = name/**/buf + 1; \
        }


  and then elsewhere in the main program it does a call like:

   check_size (code);

where there are variables named e_code, l_code, codebuf and s_code already
declared.  What would be the equivalent MSC 5.1 code to do this?  I tried to
remove the offending /**/ but then I get a compile error w/e_name, etc...

  Any suggestions (apart from hard code it)??

-- 
                                          Bruce (bkahn@archive.webo.dg.com or
                                                 kahn@adam.dg.com)
  
  Standard disclaimers apply, except where prohibited by law...

epames@eos.ericsson.se (Michael Salmon) (12/07/90)

In article <1197@dg.dg.com> Bruce Kahn writes:
>
>#define check_size(name) \
>        if (e_/**/name >= l_/**/name) { \
>            register nsize = l_/**/name-s_/**/name+400; \
>            name/**/buf = (char *) realloc(name/**/buf, nsize); \
>            e_/**/name = name/**/buf + (e_/**/name-s_/**/name) + 1; \
>            l_/**/name = name/**/buf + nsize - 5; \
>            s_/**/name = name/**/buf + 1; \
>        }
>
>
>  and then elsewhere in the main program it does a call like:
>
>   check_size (code);
>
>where there are variables named e_code, l_code, codebuf and s_code already
>declared.  What would be the equivalent MSC 5.1 code to do this?  I tried to
>remove the offending /**/ but then I get a compile error w/e_name, etc...
>
>  Any suggestions (apart from hard code it)??
>
As you worked out the intention was to concatenate a string literal
with a variable. ANSI compilers have a more portable way of doing it,
if memory serves me correctly it is ##. Check the manual it will give
you the details. I believe that it is called stringizing. I hope that
this is of help.

Michael Salmon
L.M.Ericsson
Stockholm