LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 02-08-2007, 04:09 PM   #1
Tischbein
Member
 
Registered: Oct 2006
Distribution: debian
Posts: 124

Rep: Reputation: 15
C pre-preprocessor or preprocessor replacement


Hello All,

Do any of you use either a non-standard C preprocessor or a pre-preprocessor? If so, could I take a show of hands of how many do and what kind of setup you use?

To clarify, this is an imaginary example in which bash is used as the pre-processing language:

Code:
#!/bin/generic_pre /bin/bash /usr/lib/generic_pre/bash_defs
#
#for i in alpha beta gamma
#do
#  DEFINE FUNCTION ${i}
#  DEFINE STRING \"${i}\"

   printf ("The function I am about to run is called " STRING "\n");
   FUNCTION;

#done
I know that the gcc preprocessor can do all sorts of clever tricks but there have on several occasions been times when I've not only wanted but I think, after careful consideration, NEEDED a better preprocessor. Making one is no big deal, but interoperability with other people doing the same thing seems a worthwhile goal.

I have a pretty good idea of what I think I want, but I don't know what's out there. There might even already be a generic way of using scripting languages for C preprocessing for all I know.

Regards, Hasenbein

Last edited by Tischbein; 02-08-2007 at 04:12 PM.
 
Old 02-09-2007, 08:59 AM   #2
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
When you compile gcc there is an option for 'with-cpp' that will create a bash script which substitutes cpp -If I remember correctly.
 
Old 02-10-2007, 09:20 AM   #3
grumpf
Member
 
Registered: Dec 2005
Distribution: just replace windows with linux
Posts: 38

Rep: Reputation: 15
actualy it depends what you exspect. CPP is more or less and search/replace
that can easly be extended using bash/perl/awk; you name it.

When you expect help for a given problem maybe you should explain the
problem.
 
Old 02-11-2007, 11:38 AM   #4
Tischbein
Member
 
Registered: Oct 2006
Distribution: debian
Posts: 124

Original Poster
Rep: Reputation: 15
Here's a (second) toy problem:

Suppose I have a large program with lots of C files.

I have debugging code in all the files. Debug code is prefixed by DB and perhaps some ids, e.g.:

Code:
DB  printf(stderr, "Started on this file");
DB(3) printf(stderr, "doingstuff");
DB(anchor) printf(stderr, "doingotherstuff");
DB(3,anchor) printf(stderr, "never done this before!")
I have a .h file which controls debug output. Debugging can be switched on & off for each file, for each id, or for a combination of both:

Code:
DB_ON shluck.c 3  # db code in the indicated file at level 3.
DB_ON anchor      # db code with the anchor keyword
Finally, the code has to run fast, so the debug code really does have to be taken out by the preprocessor, not replaced by a C runtime check.

What tools does the C preprocessor have to help with this? Well, it has keywords for the current file name and it has concatenating ability. So it's pretty easy to make a runtime check for filenames:

#define DB if ( debug_##__FILE )

(or whatever it is - my trusty preprocessor manual is out of reach)
A couple of us put our heads together a few months ago (when I asked this one) and worked out how to deal with the keywords as well, and the result was really ugly. Also, it yet again involved runtime checks, so ran dog slow.

So, how do I do it using purely the pre-processor?

If I could use bash or perl as a preprocessing language I'd be happy.

I'll check the with-cpp option, thanks gnashley.
grumpfs: You mention that it's not only possible but easy to extend the pre-processor with other scripting languages. That sounds interesting. Can you show me some examples, or a page with a mini-essay on how to do this?

Regards, Hakenbein

Last edited by Tischbein; 02-11-2007 at 11:40 AM.
 
  


Reply



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
command to find the preprocessor hegdeshashi Linux - General 1 01-19-2007 10:50 AM
Snort BO Preprocessor Vulnerability Capt_Caveman Linux - Security 0 10-19-2005 01:33 AM
No C++ preprocessor Mandrake 10.1 ? TotalDefiance Linux - Software 1 11-04-2004 10:41 PM
C preprocessor error mokojin Slackware 7 11-01-2004 02:56 AM
Can the C preprocessor do this? MadCactus Programming 2 08-24-2004 01:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration