abusing the c compiler

7 September 2010 8:43 PM (larceny | scheme | ffi)

code reading

Today I found something really neat in Larceny's foreign function interface. The deal is that often times you need to parse a C structure or a preprocessor definition, and man, parsing C makes a body feel lazy. What's a hacker to do?

Larceny has an amusing take on this problem. The code looks straightforward enough:

;; parse out ent->d_name as a string
(define (dirent->name ent)
  (define-c-info (include<> "dirent.h")
    (struct "dirent" (name-offs "d_name")))
  (%peek-string (+ ent name-offs)))

The define-c-info block calculates name-offs, which is the offset of d_name in the dirent structure. %peek-string is something internal to Larceny that takes a memory address of a NUL-terminated C string and returns a Scheme string.

I had imagined, looking at this, that they had some kind of database of the headers and such, and in a sense they do -- in the form of the C compiler. define-c-info is a macro that runs the C compiler at macro expansion time, compiling and running a generated C program that spits out the relevant information as an s-expression on its stdout.

some people like diagrams

So in this case, if the d_name field starts 11 bytes into the structure, the generated C program will print out (11) on its stdout, and that number gets read in and inserted into the program. In that way dirent->name expands to something like:

(define (dirent->name ent)
  (define name-offs 11)
  (%peek-string (+ ent name-offs)))

Cool, no? The C compiler is only needed at compile-time, not at run-time.

Further details can be seen at Felix Klock's 2008 paper on Larceny's FFI.

116 responses

  1. jpc says:

    The first time I have seen the idea to use the C compiler like that was in Scheme->C [1] compiler (cdecl/sizeof.c). But to be precise it did it only once and afterwards used the collected sizeof+padding info.

    There is also a very neat idea like this in the Go implementation. [2] They parse the debugging information from the assembly output of the host compiler.


  2. andrei says:

    Although in Scheme->C that's a bit pointless and one day when I have time it will get simplified. Since we can inline C code we can just use the offsetof macro.

  3. robux generator says:

    The designer of the hack tool must be able to guarantee you that the web servers used have a long-term link with Roblox games. It is rather straightforward making use of the free roblox robux generator.

  4. opera browser says:

    If you are getting any errors to Download Opera Mini for PC or Laptop using bluestacks app gamer after that you can follow this below motioned method to complete this pending procedure.

  5. Hearts play online says:

    Hearts solitaire play online is best single player cards games, this is the best game you can play online at home, at your office in your free time

  6. says:

    Play styles and preferences across xbox one and MIcrosoft pc games. at the heart of direct x 12 is than ever before maximizing use of existing graphics hardware.

  7. playbox hd apk says:

    nice article, if you want to get free playbox hd apk, click on the link provided.

  8. windows 10 support says:

    this is the first time that I have seen the code like this .this is really a good information about the compiler.

  9. says:

    The function will tell the pre-processor usage and expects an argument in the middle of the function. C is a high level language and it is used by all the major services to develop software and operating systems. Pre processor usually runs the program in the kernel space and it only accepts binary values.

  10. how to get free robux says:

    hey guys if you are a gaer and want some interesting game then try roblox

  11. robux generator says:

    Hey guys I like to play online games like free robux game on internet free of cost with full fun and enjoy if you are interested to play so click on our page and play online this game.

  12. Survey Remover Tool says:

    really nice tool here to remove or bypass surveys online.

  13. says:

    thanks for the awesome article.

  14. No Guarantor Loans says:

    Very nice Article! Thanks for sharing.

  15. Nick Patel says:

    in between the online compilers ms outlook support is one of the useful compilers, and it is compiling with the single line, so the bug detection can be very easy with this type of compiler.

  16. HP Support says:

    This article is good. I have also an HP printer and I am facing issues can anyone tell me how can clear up HP LJ4100 error from Hp printer. And also printer going for walks too slow give some higher answer!!!

  17. Printer Offline Windows 10 says:

    These are not recommended in DTG printing because the white underbase will be showing through those semi-transparencies, creating a very speckled look, which can often look poor quality.

  18. 0xc0000225 says:

    Hey guys I like to play online games like free robux game on internet free of cost with full fun and enjoy if you are interested to play so click on our page and play online this game.

  19. uk assignment says:

    I had inconveniences when I utilized nexon launcher since it introduced maple on programfiles. I would experience the ill effects of stammering in RnJ and when murdering swarms. I uninstalled and downloaded maple straightforwardly from the site and introduced it in a registry. Runs better now and I don't slack like I used to. The slack from opening the world guide or missions has dependably been there for me. Simply persist it

  20. roblox hack says:

    Hey really such a amazing post dear. And guys if you want to hack roblox then must try my link.

  21. Saim Thomus says:

    One critical culmination is that, since Turing fulfillment permits the meaning of non-ending calculations, it is conceivable to express "C++ programs" whose accumulation is non-ending, which additionally infers that the compiler produces neither mistake messages nor question code. (By and by, compilers have a limit on format instantiation profundity to maintain a strategic distance from non-end.) Telstra Helpline
    In the accompanying I am will show several code bits containing non-ending format calculations, and how GCC (g++ 4.8.2) and Clang (clang++ 3.3) handle them.

  22. dialprintersupport says:

    HP Printer Technical Support team is a group of experts which deal with technical issues in your printer. In case you need any technical support contact us by dialing our toll-free number +1-888-902-8333 or visiting our website

  23. ishagarg says:

    I have recently talked about the latest updated blog, This is one of the fabulous ways of serving the best choices thanks lot..

  24. Bangalore call Girls says:

    Happy to see this amazing article, you are giving us inspiration, inspiration. The extraordinary degree that you are scattered here is amazing. It helped me to refine me a ton. A responsibility of gratitude is for your efforts and support, keep sharing such things for each situation. Your blog is appreciated !!

  25. Hyderabad Escorts says:

    Thank you for posting such a great article! I found your website perfect for my needs. It contains wonderful and helpful posts. Keep up the good work!. Thank you for this wonderful Article!

  26. Brother Printer support number says:

    We are independent third party brother printer tech support provider in the USA. We have a team of certified experts for solving out the printer issues. We provide users the best possible solution in less time we also solve error via remote access. Dial Brother Printer support number +1-800-684-5649 ask your query.

  27. Printer Customer Support says: Experts gives the best and most reliable solutions for your printers. the experts can be reached anytime for help.

  28. HP printer repair near me says:

    Larceny that takes a memory address of a NUL-terminated C string and returns a Scheme string.

  29. chocolartshop says:

    I learn scripting languages step by step since it is so convoluted and the new individual did not learn at one time. I am hoping to gain more from you.

  30. utorrent download says:

    Currently, uTorrent's software is considered safe and free of dangerous malware. The primary risk of using uTorrent comes not from the software itself, but the risk of downloading dangerous or infected torrents from unknown sources.

  31. buy real targeted instagram followers says:

    Buy Instagram and place the list of the most popular satanin. Twitter, youtube, facebook and igtv services are available. Buy quality and real followers. You can place an order with our 24/7 customer service support.

  32. best tent camp in jaisalmer says:

    This program can be designed to do nearly everything. The setup is finished amid aggregate time by composing in C code what one might want the program to perform. An unimportant model is given in the 'how to order' segment, yet the conceivable outcomes are unmistakably restricted just by your creative ability and programming aptitudes

  33. stream complet says:

    Les extraterrestres ont envahi la Terre. Occupée, Chicago se divise entre les collaborateurs qui ont juré allégeance à l’envahisseur et les rebelles qui les combattent dans la clandestinité depuis dix ans.
    regarder ce film en streaming gratuit sur streamcomplet

  34. HP Printer Setup says:

    Once you buy a new HP printer it is very necessary to setup it correctly to get printout easily. If you are not able to configure your HP printer correctly then contact experts to resolve HP Printer Setup related issues. You will save your time by having expert’s guide to setup printer.

  35. Sockshare says:

    Its an amazing website, really enjoy your articles. Helpful and interesting too. Keep doing this in future. I will support you.

  36. GoStream says:

    No one can refuse the value of your article, but should you add more picture for reader can easily understand about what you want to transmit. Anyways, thank for your shared.

  37. XMovies8 says:

    Your opinion are very interesting, attractive article, so i shared it on my facebook. Promise that a lot of people will enjoy it.

  38. Jav Hot says:

    Thanks for sharing this wonderful post, blog comments really help us grow because we are building relationship with others and also it help us build SEO and also comments makes our blog alive and google also index comments. I would appreciate if you include my blog to your list of blog commenting sites.

  39. Canon Printer Offline says:

    Printer offline is one of the most common issues faced by printer users. Some technical peoples resolve this issue by yourself. But sometimes it is hard for the non-technical person to resolve this issue. You can get help from experts to resolve Canon Printer Offline issue.

  40. Jack pontiing says:


  41. AOL Gold download says:

    AOL desktop gold is famous software that enhances the security of email application. Installation of this software is not an easy task. To understand how to perform AOL Gold download connect to our experts. A team of experts is always available to handle customers’ queries.

  42. printer offline windows 10 says:

    The most common solution we hear is to turn off the printer and let it cool down for a few minutes. It might be caused by some foreign debris inside the rollers or due to paper jam to it has to be removed.

  43. brother printer error 48 says:

    hello guys
    this blog is very nice thank you so much sharing this article
    if you are facing problem related to brother printer error 48 then you can contact our websites.

  44. Login issues on mobile with Yahoo mail app? says:

    Today’s generation prefers to check emails on the go as they have to stay connected with their online accounts all the time. According to the statistics report of Litmus “Email Client market Share Trends for 2017”; 51% of all email is opened on the mobile app. Receiving and replying an urgent email on mobile is more convenient for this hyperactive people.

  45. Charlie William says:

    Get Certified Online Help for Roadrunner Email

    Roadrunner email is a famous email service used all over the world to send/receive emails. There may be a possibility of having technical issue with the roadrunner email like login issue, forget password and much more. You can get help by contacting Roadrunner Support Number to resolve all the issues related to Roadrunner email.

  46. Reset Yahoo Mail Account password says:

    However, sometimes it happens that you forgot your password or somebody hacked your Yahoo account. So, in this situation you completely become unable to have access to your Yahoo account. Anyway, you should not get worried as you can easily reset the password of your Yahoo account and could again have access of it. If you have forgotten the password of your Yahoo then just go through this blog to reset the Yahoo password in a simple manner.

  47. Lisa Rose says:

    Changing profile picture and the banner images frequently in Facebook is the mantra to break the monotony of life. With the advent of the mobile camera, people like to click pictures whenever they want. The selfie you take with your mobile camera or the perfect panorama shot with your new DSLR camera, the best place to display the creativity is your Facebook account. The steps to change the profile and cover picture are the mandatory knowledge one must have. If you still don’t know how to change it; we are here helping you out by providing the step by step guidance to change the pictures.

  48. film streaming says:

    1987 – Alors qu’il est en fuite, l’Autobot Bumblebee trouve refuge dans la décharge d’une petite ville balnéaire de Californie. Il est découvert, brisé et couvert de blessures de guerre, par Charlie, une ado qui approche de ses 18 ans et cherche sa place dans le monde. Et quand elle le met en marche, elle se rend vite compte qu’il ne s’agit pas d’une voiture jaune ordinaire.
    film streaming complet


    I must say that this is a great post.Really I am impressed from this post.

  50. Samsung Printer Software Installer says:

    Follow the easy steps in the article to install drivers/software using Samsung Printer Software Installer for Windows, Network or USB Network Connections. If you are facing issues in installing connect with our experts to avail advanced help.

  51. Brother 2270dw Wireless Setup says:

    Setup wireless printing with Brother 2270dw. It is very easy to attain Brother 2270dw Wireless Setup. Follow the easy steps for Brother Printer Setup.

  52. SEO Services London says:

    Nice Post. This post provides such great knowledge about the C language and compiler is used to translate high-level language into machine language. It is all about digital marketing and Seo Services London is big name in this IT field.

  53. HP Wireless Printer Offline says:

    HP wireless printer offline issue fix with easy steps suggested by experts.

  54. Mcafee.Com/Activate says:

    Is your McAfee Antivirus expired or about to expire? Then it is the right time to act fast to activate your antivirus as quickly as possible. In the times of harmful virus attacks and cyber-attacks, it is significant to keep your system safe and running. Therefore, it is better to adapt the ways to activate, as not doing so will surely make your system vulnerable against various threats. If you are not acquainted with the right procedure for activating McAfee antivirus, then you should visit Mcafee.Com/Activate or consider taking help from McAfee support team. At here, you will get the chance to meet with deft team of technicians who will assist you out in doing the needful.

  55. ikka23 says:

    Nice Post. This post provides such great knowledge about the C language and compiler is used to translate high-level language into machine language

  56. kids123 says:

    I really happy found this website eventually. Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such blog.

  57. HP support phone number says:

    Such a great piece of content and helpful website! Attractive information on your blog, thank you for taking the time and share with us. +1-844-802-7535 Call our Toll-Free HP support phone number regarding your HP printer related issues.

  58. poul23 says:

    I really happy found this website eventually. Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such blog.

  59. mark123 says:

    i liked your comment thanks for sharing

  60. says:

    Every software comes with a free and paid trail version. The free version of any software has the limited functionality and features but paid version has complete features. Mcafee antivirus software also comes with a paid version. You should go to to activate your premium Mcafee antivirus software. You can also avail help from experts to activate it easily.

  61. whitemushroom says:

    Great post ! thanks for sharing .! this site are good after awesome.

  62. Film Streaming says:

    Very informative content. Thanks for sharing this valuable content with us.

  63. indianvisa says:

    nice post ! thanks for sharing.

  64. Money says:

    so I just wanted to give a quick shout out and say I genuinely enjoy reading your article

  65. chopal says:

    so I just wanted to give a quick shout out and say I genuinely enjoy reading your articles

  66. satta matka says:

    your site to amazing . good info ! thanks for sharing

  67. says:


  68. says:

    We all have our personal and business data in the PC to complete our daily task. To secure our data from virus and malware, Norton is the recommended software by the experts.

  69. jyoti kirar says:

    I like your post. I like it. For over 25 years David Soble has provided no nonsense legal advice to banks, lenders and consumers alike, in the areas of commercial and residential real estate, business and residential lending and contract matters.

  70. math puzzel says:

    The post you share is fabulous its very useful thanks for sharing.

  71. jain singh says:

    Please stay us up to date like this. Thank you for sharing

  72. HP wireless printer setup says:

    Nice Post Really I enjoy this post thank you for the post.

  73. spearfishing gear says:

    the largest spearfishing gear store in the market at budget-friendly prices.

  74. Quicken Help says:

    If you are frustrated to fix quicken accounting issues so, you can connect with us and get Quicken help with reasonable price.

  75. Web Development Services says:

    Thanks for sharing the great article I also bookmark this page. And I wish you write more about this type of blog in the future...

  76. achan123 says:

    I have recently talked about the latest updated blog, This is one of the fabulous ways of serving the best choices thanks lot..

  77. Garmin GPS Update says:

    If you’re facing any issues related to Garmin GPS update, our Garmin support professionals are very experienced to solve this issue instantly.

  78. Dellinspiron52 says:

    This post is very nice thanks for sharing its very good post

  79. sattamatka52 says:

    Thanks for sharing this blog here. It seems really very informative. It’s really a great and helpful piece of information. I’m satisfied that you just shared this helpful information with us.

  80. printer repair says:

    You have shared the informative post and suggestion for those people who don't even know about it project to keep it up thanks for sharing.

  81. James mark says:

    Unable to sign in? Dial Verizon Wireless Support Number
    Encountering sign in issues? Don’t panic, we have solutions to your problem. There are many issues that cant be resolved on your own. You require a technical person as the issue might be complicated. For complex to simple queries, make sure you report your query instantly to our Verizon Wireless Support Number. They are capable enough in handling sign-in issues. To get instant outcomes, it is advisable to engage with our Verizon Wireless Support Number.

  82. ITS llc says:

    Thanks for the information. If you have any doubt regarding accounting just contact internal tax service.

  83. uber suggest tool says:

    nice post ! thanks for sharing.

  84. mike says:

    good and aweosome information that you shared. I like the contents of the post.

  85. garter wallet says:

    It’s really a great and helpful piece of information.

  86. body shaper for women says:

    Thank you so much for sharing a great information. I appreciate your time and effort in your work. Keep posting.! thank you !

  87. home Purchase Agreements says:

    Post is very good thanks sharing its very awesome post thankyou

  88. seo specialist says:

    The information you shared with us was very helpful, thank you very much. Great post, Thanks for providing us this great knowledge, Keep it up.

  89. love123 says:

    Thank you so much for sharing such a useful information. I will definitely share this with others

  90. box mod vapor says:

    This post is very good thanks for sharing its very amazing post

  91. inspirational quotes love says:

    I adore it when folks come together and share opinions, great site,
    keep it up

  92. kundan12 says:

    Thank you so much for sharing such a useful information. I will definitely share this with others

  93. googleadstraining123 says:

    It’s really a great and helpful piece of information. I’m satisfied that you just shared this helpful information with us.
    Please stay us up to date like this. Thank you for sharing

  94. Play matka says:

    I really like your post. Thanks for sharing. It is such a very amazing post...

  95. buyhighretentionviews says:

    This is a great information

  96. Comcast Email says:

    Nice post! This blog is very helpful for users, if users want to reset the comcast imap settings . This blog is extremely helpful for users. Thanks for sharing this useful blog.

  97. enstreaming - film streaming vf says:

    Actually quite Nice and Wonderful love helpful Blog Post. Much obliged for sharing this fascinating post Much appreciated!
    watch here unlimited film streaming vf at films vf

  98. van haber says:

    Van hakkında ki güncel haberlere bu sitemizden kolay bir şekilde ulaşabilirsiniz!

  99. igrice says:

    igrice za decu koja vole da provedu slobodno vreme igrajući igrice. Ukoliko želite da se opustite i odigrate neku dobru igru, na pravom ste mestu. Besplatne igrice na jednom mestu, igrajte najbolje besplatne igrice za decu i igrice za odrasle... Za Vas postavljamo najbolje igre, pridružite nam se.

  100. Bangalore Escorts says:

    Welcome to the Midnight Partner - Bangalore escort service, a popular service provider of escorts in Bangalore, for professional.

  101. says:

    HP printers, as an incredible asset for viable and solid printing with guided exactness, have become a basic prerequisite of our own just as expert life. Get your hands on the best HP printer in the market and set up the gadget followed by a lot of rules by means of . Make a point to utilize substantial qualifications to evade blunders however much as could be expected.

  102. nagpur escorts says:

    The Nagpur Escorts Services also spots connected as your girlfriend and far half inside the make any difference of sex

  103. Garmin map updater says:

    I am facing difficulties to install Garmin map updater. It has become a big technical trouble for me, so I look for online expert help. I don’t have full technical knowledge to install Garmin map updater on my computer system.

  104. Aiden Jangra says:

    Thanks for posting this info. I just want to let you know that I just check out your blog and I find it very interesting and informative. I can't wait to read lots of your posts. Know about HP 5520 Printer Not Printing Black.

  105. Roku Com Link says:

    Thank you because of this informative blog since it's really assistance, I like blog. Wonderful! Thank you for sharing an informative information! If you are planning to upgrade your older TV to Smart TV, then you must purchase Roku instead. Roku is a budget-friendly streaming media player. They are available 24X7 to pick up your phone call. Post click here Roku com/link!

  106. Chennai Escorts says:

    She is a high society young lady comes into this calling just to win some extra bucks of money. She is low upkeep appears too.

  107. HP officejet 5255 driver says:

    If you want to upgrade HP officejet 5255 driver to the latest version, you can call our trained technical experts to upgrade your driver successfully. Our live technical support team is available 24 hour to help you for any type of technical difficulty.

  108. Geek squad tech support says:

    Remove snags with your devices at Geek Squad Tech Support. You can approach the experts round the clock at your own convenience. Feel free to reach Geek Squad for all issues regarding your gadgets.

  109. Geek squad protection plan says:

    Geek Squad Protection covers your devices even after your manufacturer warranty lapses. Our experts extend you repairs and safe coverage for damages for the wide range of products.

  110. Geek squad tech support says:

    Really appreciate your post

  111. Accounting assignment help says:

    Accounting assignment help allows you to connect with experts and get effective assistance for your project submission. Don’t forget to check out all the features before buying the services of online assignment help for your accounting papers.

  112. how to cancel pof membership says:

    This is extremely helpful info!! Very good work. Everything is very interesting to learn and easy to understand. Thank you for giving information.

  113. Bangalore Female Escorts says:

    Thanks for making such a cool post which is really very well written.will be referring a lot of friends about this.Keep blogging.

  114. TriptoVietnam says:

    Hello! This is my first visit to your blog! This is my first comment here, so I just wanted to give a quick shout out and say I genuinely enjoy reading your articles

  115. Malaysia passport renewal says:

    Nice post ! I love its your site after reading ! thanks for sharing.

  116. Pest Control Watertown NY says:

    Working with some of the most advanced and environment-friendly tools and techniques our Pest Control Watertown NY specialists stop pest infestations right at the source and clean out pests that might already be rooted within your home or office premises.

Leave a Reply