Re: Can an M4-program read data out of an C-program?

"Raphael 'kena' Poss" <[email protected]>
Newsgroups gmane.comp.gnu.m4.general
Message-ID <[email protected]>
Op 19 mrt 2010, om 15:24 heeft Amaury Ampe het volgende geschreven:

> I'm quite new to programming in general and completely new to M4, so any help would be most welcome.

In your controller program in C:

  int thevalue = 1234;

  const char cmd[100];
  sprintf(cmd, "m4 -DPPCVAL=%d yourfile.m4 >thecode.c", thevalue);

In your template file in M4:

  .... (some code already there...) ...

       asm("your assembly stuff using PPCVAL ....");

  ....


to make a long story short: use -D with m4 to define a macro on the command line. Use this macro by name in your generated C code. M4 will replace the macro by its value even when it occurs within a C string.


-- 
Raphael 'kena' Poss · [email protected] · +31 20 525 7559
UvA · FNWI · IvI · CSA · 1098XG 107 Amsterdam (NL)
z = \f. (\x. f (\y. x x y)) (\x. f (\y. x x y))
There is no spoon, only fork() and vfork().
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.