LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-06-2005, 04:39 AM   #1
deveshs
LQ Newbie
 
Registered: Mar 2005
Location: Pune India
Distribution: FC3, RH9
Posts: 12

Rep: Reputation: 0
Angry using m4 macro processor


Hi all,

I am trying to extract some part of C source code defined under certain Macro statements
for example this is a code

#include<stdio.h>
#include<unistd.h>

int main(void)
{

int my_int = 10 ;

#ifdef TEST_MACRO
int his_int = 20 ;
#else
int other_int = 40;
#endif

printf( "Test Program\n");

#ifdef TEST_MACRO
printf("his_int=%d\n",his_int);
#else
printf("other_int=%d\n",other_int) ;
#endif

printf("my_int=%d\n",my_int);

return 0 ;

}

Now after some processing using m4 I want following type of output

#include<stdio.h>
#include<unistd.h>
int main(void)
{

int my_int = 10 ;


int his_int = 20 ;




printf( "Test Program\n");


printf("his_int=%d\n",his_int);




printf("my_int=%d\n",my_int);

return 0 ;

}

using gcc -E is ofcourse one way of doing this but Is it possible using m4?
Please any body tell me !!!
 
Old 10-10-2005, 12:06 AM   #2
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
I don't know what m4 is, but it is also posible by running GCC with -DTEST_MACRO flag. Like so:

gcc -DTEST_MACRO -o myprog input.c
 
Old 10-10-2005, 04:24 AM   #3
deveshs
LQ Newbie
 
Registered: Mar 2005
Location: Pune India
Distribution: FC3, RH9
Posts: 12

Original Poster
Rep: Reputation: 0
Hi _Nerd, Thanks for replying,
m4 is a generic macro processor. For more information on this please refer to the man page of this command

Yes, you are right using your solution I will get compiled ELF executable file. But my requirement is not that, I need output in the form of c soruce itself and removed unwanted code part.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
#defining a macro inside a macro? saravkrish Programming 1 05-24-2005 09:48 PM
Installing Linux on a dual processor machine (only one processor detected) rocordial Linux - Hardware 1 11-27-2004 02:16 AM
4 processor listings in cpuinfo on dual processor system. atticboy1 Linux - Hardware 2 02-08-2004 06:35 PM
xinetd 100% utilization on one processor on a two processor system red hat 9 garnold Linux - General 0 02-02-2004 01:47 PM
Kernel Panic on Dual Processor Motherboard with only 1 Processor olar Linux - Software 1 10-13-2001 03:57 PM


All times are GMT -5. The time now is 10:56 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration