# Two Lines of C in Ruby Source

**URL:** <https://www.ruby-forum.com/t/two-lines-of-c-in-ruby-source/64367>\
**Category:** Ruby\
**Created:** [January 23, 2006, 8:23am UTC](https://www.ruby-forum.com/t/two-lines-of-c-in-ruby-source/64367 "2006-01-23T08:23:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [January 23, 2006, 8:23am UTC](https://www.ruby-forum.com/t/two-lines-of-c-in-ruby-source/64367/1 "2006-01-23T08:23:46Z")

</div>

Hello,

Can somebody tell me what these lines of code mean?

extern int snprintf \_\_((char \*, size\_t n, char const \*, …));  
extern int vsnprintf \_((char \*, size\_t n, char const \*, va\_list));

I am confused over what \_, \_\_, and … mean.

They are in missing.h lines 134 - 135

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [January 23, 2006, 8:32am UTC](https://www.ruby-forum.com/t/two-lines-of-c-in-ruby-source/64367/2 "2006-01-23T08:32:54Z")

</div>

Hi,

At Mon, 23 Jan 2006 16:20:59 +0900,  
Brian T. wrote in [ruby-talk:176520]:

> I am confused over what \_, \_\_, and … mean.

See defines.h for \_ and \_\_. Look for a tutorial of C for …

Ruby source and extensions are not good as a tutorial.

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [January 24, 2006, 9:53am UTC](https://www.ruby-forum.com/t/two-lines-of-c-in-ruby-source/64367/3 "2006-01-24T09:53:38Z")

</div>

> See defines.h for \_ and \_\_.  
> Thank you for the pointer. I found the defines.

#ifdef \_\_cplusplus

# ifndef HAVE\_PROTOTYPES

# define HAVE\_PROTOTYPES 1

# endif

# ifndef HAVE\_STDARG\_PROTOTYPES

# define HAVE\_STDARG\_PROTOTYPES 1

# endif

#endif

#undef \_  
#ifdef HAVE\_PROTOTYPES

# define \_(args) args

#else

# define \_(args) ()

#endif

#undef \_\_  
#ifdef HAVE\_STDARG\_PROTOTYPES

# define \_\_(args) args

#else

# define \_\_(args) ()

#endif

It looks like if \_\_cplusplus is not defined, an empty argument field is  
outputted. If \_\_cplusplus is defined, the arguments are outputted by the  
preprocessor.

… is a variable argument. stdarg.h is required for this.  
More information can be found at  
[http://www.thinkage.ca/english/gcos/expl/c/incl/stdarg.html](http://www.thinkage.ca/english/gcos/expl/c/incl/stdarg.html)

> Ruby source and extensions are not good as a tutorial.  
> I’m trying to find out where the File name and line number of methods  
> are  
> stored. So far my search has lead me to look in the backtrace function  
> in  
> eval.c: line 6094.

If you have any pointers to lead me in the right direction, I would  
appreciate it very much.

Of course, looking at the ruby c source requires me to learn some c. 🙂

Thank you,  
Brian T.

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [January 24, 2006, 7:18pm UTC](https://www.ruby-forum.com/t/two-lines-of-c-in-ruby-source/64367/4 "2006-01-24T19:18:23Z")

</div>

Brian T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> I’m trying to find out where the File name and line number of methods are  
> stored. So far my search has lead me to look in the backtrace function in  
> eval.c: line 6094.

Spoiler warning:  
[http://ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/140058](http://ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/140058)

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [January 24, 2006, 1:41pm UTC](https://www.ruby-forum.com/t/two-lines-of-c-in-ruby-source/64367/5 "2006-01-24T13:41:04Z")

</div>

On Tuesday 24 January 2006 09:53, Brian T. wrote:

> #ifdef HAVE\_PROTOTYPES
> 
> # define \_(args) args
> 
> #else
> 
> # define \_(args) ()
> 
> #endif  
> Are there still compilers that don’t support function prototypes?

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [January 25, 2006, 5:44am UTC](https://www.ruby-forum.com/t/two-lines-of-c-in-ruby-source/64367/6 "2006-01-25T05:44:19Z")

</div>

> Spoiler warning:
> 
> [http://ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/140058](http://ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/140058)

Thank you for your help Christian.

Would there be a way to access the Node struct from a Ruby object?

My objective is to find all of the file and line numbers of the class,  
module, and method definitions.  
To me, it looks like it would require significant rewriting of the Ruby  
core  
to easily achieve this.

The reason is I’m looking at  
#define NEW\_METHOD(n,x) NEW\_NODE(NODE\_METHOD,x,n,0)  
…  
#define NEW\_CLASS(n,b,s) NEW\_NODE(NODE\_CLASS  
#define NEW\_SCLASS(r,b)  
NEW\_NODE(NODE\_SCLASS,r,NEW\_SCOPE(b),0),n,NEW\_SCOPE(b),(s))  
#define NEW\_MODULE(n,b) NEW\_NODE(NODE\_MODULE,n,NEW\_SCOPE(b),0)

in node.h

They are all called in parse.y, parse.c, class.c, and eval.c  
It looks like set\_trace\_func is the best way to achieve this goal.

Thank you,  
Brian T.

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [January 25, 2006, 5:02pm UTC](https://www.ruby-forum.com/t/two-lines-of-c-in-ruby-source/64367/7 "2006-01-25T17:02:52Z")

</div>

Brian T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> > Spoiler warning:
> > 
> > [http://ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/140058](http://ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/140058)
> 
> Thank you for your help Christian.
> 
> Would there be a way to access the Node struct from a Ruby object?

[http://rubystuff.org/nodewrap/](http://rubystuff.org/nodewrap/)

---

<div class="post-metadata">

**Author:** ![bct](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/6a8cbe/32.png) [@bct](https://www.ruby-forum.com/u/bct)\
**Post date:** [January 27, 2006, 6:27pm UTC](https://www.ruby-forum.com/t/two-lines-of-c-in-ruby-source/64367/8 "2006-01-27T18:27:44Z")

</div>

Thank you Christian. This is really neat.
