Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > looking for a clever preprocesser solution

Reply
Thread Tools

looking for a clever preprocesser solution

 
 
Mark P
Guest
Posts: n/a
 
      12-21-2005
I have a header file and want to expose only a limited portion of that
file to SWIG (all you need to know is that when SWIG processes a file
the preprocessor macro SWIG is defined). Otherwise I want to expose the
entire file. Here's a schematic 5 line example; let's suppose I only
want to expose lines 2 and 4.

line 1
line 2
line 3
line 4
line 5

One option is:

#ifndef SWIG
line 1
#endif

line 2

#ifndef SWIG
line 3
#endif

line 4

#ifndef SWIG
line 5
#endif

This works, but what I don't like about it is that's it's phrased in the
"negative" and highlights all the things that aren't exposed to SWIG.

What I'd rather do is something like:

#ifdef SWIG
"ignore everything except labelled code"

line 1

// label on
line 2
// label off

line 3

// label on
line 4
// label off

line 5
#endif

Is there any clever trick to make this work?
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      12-21-2005
Mark P wrote:
> I have a header file and want to expose only a limited portion of that
> file to SWIG (all you need to know is that when SWIG processes a file
> the preprocessor macro SWIG is defined). Otherwise I want to expose the
> entire file. Here's a schematic 5 line example; let's suppose I only
> want to expose lines 2 and 4.
>
> line 1
> line 2
> line 3
> line 4
> line 5
>
> One option is:
>
> #ifndef SWIG
> line 1
> #endif
>
> line 2
>
> #ifndef SWIG
> line 3
> #endif
>
> line 4
>
> #ifndef SWIG
> line 5
> #endif
>
> This works, but what I don't like about it is that's it's phrased in the
> "negative" and highlights all the things that aren't exposed to SWIG.


So, flip it. You can always make negative positive by using 'not'...

> What I'd rather do is something like:
>
> #ifdef SWIG
> "ignore everything except labelled code"
>
> line 1
>
> // label on
> line 2
> // label off
>
> line 3
>
> // label on
> line 4
> // label off
>
> line 5
> #endif
>
> Is there any clever trick to make this work?


No. Your "label on" is still going to be an #ifdef, and "label off" --
#endif. So, you can do

#ifndef SWIG
#define MORETHANJUSTSWIG
#endif

#ifdef MORETHANJUSTSWIG
line 1
#endif

line 2

#ifdef MORETHANJUSTSWIG
line 3
#endif

line 4

#ifdef MORETHANJUSTSWIG
line 5
#endif

Now, it's only partially negative. It still "highlights" something, just
like your "label on" and "label off" do. My question is, so damn what?

If you can, extract your lines 2 and 4 into a separate file and include it
here, and hide your 'ifdef SWIG' there.

All in all, if you need to conditionally compile something, you're stuck
with #ifdef or #ifndef or #if, and nothing else is going to help you. Get
over it.

V
 
Reply With Quote
 
 
 
 
Mark P
Guest
Posts: n/a
 
      12-21-2005
Victor Bazarov wrote:
> Mark P wrote:
>
>>
>> This works, but what I don't like about it is that's it's phrased in
>> the "negative" and highlights all the things that aren't exposed to SWIG.

>
>
> So, flip it. You can always make negative positive by using 'not'...
>
>>
>> Is there any clever trick to make this work?

>
>
> No. Your "label on" is still going to be an #ifdef, and "label off" --
> #endif. So, you can do
>
> #ifndef SWIG
> #define MORETHANJUSTSWIG
> #endif
>
> #ifdef MORETHANJUSTSWIG
> line 1
> #endif
>
> line 2
>
> #ifdef MORETHANJUSTSWIG
> line 3
> #endif
>
> line 4
>
> #ifdef MORETHANJUSTSWIG
> line 5
> #endif
>
> Now, it's only partially negative. It still "highlights" something,
> just like your "label on" and "label off" do. My question is, so damn
> what?
>


By negative I didn't mean ifdef vs. ifndef, I meant that I had to wrap
all the non-SWIG stuff instead of the SWIG stuff. In practice, the
portions that are meant to be exposed to SWIG are small, and the
portions that aren't to be exposed are large, so it's easier to
comprehend IMO if only the SWIG portions are wrapped. In any event, I
gather that there's no clever fix here.

Thanks,
Mark
 
Reply With Quote
 
Old Wolf
Guest
Posts: n/a
 
      12-22-2005
Mark P wrote:

>
> #ifndef SWIG
> line 1
> #endif
>
> line 2
>
> #ifndef SWIG
> line 3
> #endif
>
> line 4
>
> #ifndef SWIG
> line 5
> #endif
>
> This works, but what I don't like about it is that's it's phrased in the
> "negative" and highlights all the things that aren't exposed to SWIG.


This is just a whitespace issue, surely?

#ifndef SWIG
.......
.......
line 1

#endif
line 2
#ifndef SWIG

line 3

#endif
line 4
#ifndef SWIG

line 5
.........
........
#endif

 
Reply With Quote
 
Francis Glassborow
Guest
Posts: n/a
 
      12-22-2005
In article <QVkqf.40710$> , Mark P
<> writes
>I have a header file and want to expose only a limited portion of that
>file to SWIG (all you need to know is that when SWIG processes a file
>the preprocessor macro SWIG is defined). Otherwise I want to expose
>the entire file. Here's a schematic 5 line example; let's suppose I
>only want to expose lines 2 and 4.
>
>line 1
>line 2
>line 3
>line 4
>line 5
>
>One option is:
>
>#ifndef SWIG
>line 1
>#endif
>
>line 2
>
>#ifndef SWIG
>line 3
>#endif
>
>line 4
>
>#ifndef SWIG
>line 5
>#endif
>
>This works, but what I don't like about it is that's it's phrased in
>the "negative" and highlights all the things that aren't exposed to
>SWIG.
>
>What I'd rather do is something like:
>
>#ifdef SWIG
>"ignore everything except labelled code"


Perhaps ifdef/ifndef is the wrong choice of preprocessor directive, try:

#define SWIG 0

#if SWIG
line 1
#endif

line2

#if SWIG
line 3
#endif

line4

#if SWIG
line 5
#endif

Now you can switch suppression on and off by changing the value
associated with SWIG between 0 and 1

--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Typed Datasets and ObjectDataSource - clever solution to the scalarparameters problem? JimLad ASP .Net 3 11-30-2009 11:18 AM
PIX VPN client-to-client routing: clever ways? Jay Levitt Cisco 1 01-21-2006 06:36 AM
clever programming solution wanted Scott Rifkin Python 3 07-15-2004 10:57 PM
Completely OT, but you guys are clever - Java 3 07-15-2003 07:55 PM
Is there any clever solution? A Python 0 07-14-2003 08:10 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57