# C / C++ extensions: need all the tips/tricks you can give me

**URL:** <https://www.ruby-forum.com/t/c-c-extensions-need-all-the-tips-tricks-you-can-give-me/131480>\
**Category:** Ruby\
**Created:** [March 10, 2008, 3:22pm UTC](https://www.ruby-forum.com/t/c-c-extensions-need-all-the-tips-tricks-you-can-give-me/131480 "2008-03-10T15:22:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![emmanueloga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecae2f/32.png) [@emmanueloga](https://www.ruby-forum.com/u/emmanueloga)\
**Post date:** [March 10, 2008, 3:22pm UTC](https://www.ruby-forum.com/t/c-c-extensions-need-all-the-tips-tricks-you-can-give-me/131480/1 "2008-03-10T15:22:55Z")

</div>

Hi!

I’m looking for all available sources of information on developing ruby  
extensions. I’m not a C language expert, but I’ve worked some years ago  
as a junior C/C++ developer. For that reason, I think I could get in  
business if I find the good resources inside the mess of google results  
for “writing ruby C extensions” query…

I would like to hear your suggestions, experiences, gotchas, etc… on  
the subject as links to web pages or directly here for both:

- Essentials C (and C++) language knowledge that I will need
- Specific ruby extensions tips
- I need mostly info on 1.8.x mri, but info related to jruby and others  
will be appreciated too.
- Writing extensions in other languages. I would like info in writing  
extension in D language, for example.

DISCLAIMER: I know how to use google :-). I already did my homework…  
Still, I would like to hear suggestions from real experts (that is, YOU  
🙂 better than from a stupid computer (that is, google), that always  
spits a big amount of junk inside the useful links.

P.S.: My intent is 1) to learn this subject 2) To compile a definitive  
document/webpage/wiki/something --with proper credits attached :)-- to  
summarize the good info sources I retrieve. You may agree with me that  
info on writing C extensions is scarce and scattered all over the web.

P.S.2: I Know that the main source of information is on the ruby source  
itself and the txt files bundled. I also know of the Pickaxe chapter on  
this. The problem is that, being no C expert, is a little difficult to  
me to learn from those sources. That’s why I would also appreciate your  
recommendations on good / concise sources of C related knowledge.

---

<div class="post-metadata">

**Author:** ![emmanueloga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecae2f/32.png) [@emmanueloga](https://www.ruby-forum.com/u/emmanueloga)\
**Post date:** [March 11, 2008, 12:13am UTC](https://www.ruby-forum.com/t/c-c-extensions-need-all-the-tips-tricks-you-can-give-me/131480/2 "2008-03-11T00:13:21Z")

</div>

On Monday 10 March 2008 15:22:51 Emmanuel O. wrote:

> this. The problem is that, being no C expert, is a little difficult to  
> me to learn from those sources. That’s why I would also appreciate your  
> recommendations on good / concise sources of C related knowledge.

Well, you’ve written pretty much everything anyone could tell you on a  
generic  
question about ruby extension programming. The ruby C API is pretty  
straightforward, it is documented in file README.EXT which comes with  
ruby  
source, and as you said yourself you can find many sources on the  
subject all  
over the net. So far i wrote two extensions and i can’t think of any  
serious  
problem or a tip that wouldn’t be mentioned in the docs.

Really the best way to learn this is to just start coding, and see if  
you’ll  
hit any problems, then you can ask specifically, and i’m sure everyone  
here  
will try to help you.

Also, if you’ll start exercising your C skills, remember that C and C++  
are  
two radically different languages, that share common syntax by mere  
accident 🙂

Jan

---

<div class="post-metadata">

**Author:** ![emmanueloga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecae2f/32.png) [@emmanueloga](https://www.ruby-forum.com/u/emmanueloga)\
**Post date:** [March 11, 2008, 12:22am UTC](https://www.ruby-forum.com/t/c-c-extensions-need-all-the-tips-tricks-you-can-give-me/131480/3 "2008-03-11T00:22:51Z")

</div>

> Well, you’ve written pretty much everything anyone could tell you on a  
> generic question

Wow!!! I tried my best, but you skillfully gave me the answer I was  
trying to avoid! (no offense, just a joke! 🙂 )

You are very very right. Still, by browsing these very forums and all  
over the web I found tips like “beware of multi-threading” or “don’t do  
this when writing a binding for a c++ lib”. I’m just trying to get up to  
date tips and links that I may have loose on my research.

> Really the best way to learn this is to just start coding, and see if  
> you’ll hit any problems, then you can ask specifically, and i’m sure everyone  
> here will try to help you.

Thanks! I use to get all info I can get before starting a project.  
That’s why I asked first, but again you are right. Still would like to  
receive tips / links in advance
