# Smoking out C extension mistakes

**URL:** <https://www.ruby-forum.com/t/smoking-out-c-extension-mistakes/52070>\
**Category:** Ruby\
**Created:** [January 10, 2006, 5:20pm UTC](https://www.ruby-forum.com/t/smoking-out-c-extension-mistakes/52070 "2006-01-10T17:20:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [January 10, 2006, 5:20pm UTC](https://www.ruby-forum.com/t/smoking-out-c-extension-mistakes/52070/1 "2006-01-10T17:20:30Z")

</div>

Hi all,

Every once in a while I’ll hit a segfault that turns out to be caused by  
accidentally passing a C datatype to a macro like NIL\_P (which,  
naturally, I  
can’t duplicate with a simple example, but recently occurred in  
win32-eventlog).

Anyhoo, say I have something like this:

char\* foo = “hello”;  
if(NIL\_P(foo)) /\* whoops \*/  
…

I noticed that even compiling with gcc using -Wall -W I still don’t see  
a  
warning. Is this because it’s a macro? Is there a gcc option I can use  
to  
help me smoke these sorts of mistakes out?

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [January 10, 2006, 6:08pm UTC](https://www.ruby-forum.com/t/smoking-out-c-extension-mistakes/52070/2 "2006-01-10T18:08:45Z")

</div>

On Wed, Jan 11, 2006 at 01:18:19AM +0900, Daniel B. wrote:

> char\* foo = “hello”;  
> if(NIL\_P(foo)) /\* whoops \*/  
> …
> 
> I noticed that even compiling with gcc using -Wall -W I still don’t see a  
> warning. Is this because it’s a macro? Is there a gcc option I can use to  
> help me smoke these sorts of mistakes out?

You could use:

if(foo == Qnil)

instead of using the NIL\_P macro.

Paul

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [January 10, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/smoking-out-c-extension-mistakes/52070/3 "2006-01-10T18:11:47Z")

</div>

> > > > > “P” == Paul B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

P\> You could use:  
P\> if(foo == Qnil)  
P\> instead of using the NIL\_P macro.

#define NIL\_P(v) ((VALUE)(v) == Qnil)

🙂

Guy Decoux
