News for hackers. Stuff that matters.
Re:Show HN: Cdefs, extract function prototypes in C files to... by kr0 on Sunday August 30, 2015 @11:44AM (#10143603)
I would expect a more detailed breakdown of the individual parameters. The type, name, is it a pointer to type, etc. should all be in separate fields
Re:Show HN: Cdefs, extract function prototypes in C files to... by megalodon on Sunday August 30, 2015 @11:58AM (#10143637)
Suggestion noted! I put this together today so there is definitely room for improvement.
Re:Show HN: Cdefs, extract function prototypes in C files to... by z92 on Sunday August 30, 2015 @01:36PM (#10143956)
Breaking up parameter name, and parameter type into two separate fields will be a good update.
Re:Show HN: Cdefs, extract function prototypes in C files to... by aninteger on Sunday August 30, 2015 @02:57PM (#10144167)
Would there be something that goes the other way? Given a JSON input generates C structs and efficient serialization/deserialization for given input? It could be useful for C++ too but generate classes instead. I'm aware of gsoap which did this for wsdl and generated code for use by SOAP xml clients and servers but not sure if anyone has done this for json
Re:Show HN: Cdefs, extract function prototypes in C files to... by kylebgorman on Sunday August 30, 2015 @04:10PM (#10144347)
While it's not quite what you want (as the specification language is not JSON---it's more like C declarations), "protobufs" allow you to generate serializers and de-serializers in a number of languages.

http://github.com/google/protobuf

Re:Show HN: Cdefs, extract function prototypes in C files to... by arknave on Sunday August 30, 2015 @05:23PM (#10144526)
There's thrift, but they have a custom specification with types. It shouldn't be too hard to go from JSON to thrift though.

https://thrift.apache.org/

Re:Show HN: Cdefs, extract function prototypes in C files to... by TMSZ on Sunday August 30, 2015 @03:11PM (#10144203)
JSONedit has (experimental) C++ code generator that serializes and deserializes JSON to/from object (default name for class is "Settings" and it uses json-cpp 0.5 as parser and generator): http://tomeko.net/software/JSONedit/cpp_class_generator.php
Re:Show HN: Cdefs, extract function prototypes in C files to... by evmar on Sunday August 30, 2015 @11:46AM (#10143609)
I've used gcc-xml (apparently has been superseded by another tool now) when I've needed this sort of thing in the past. It has the advantage of being a real C parser rather than a jumble of regexes.
Re:Show HN: Cdefs, extract function prototypes in C files to... by steeve on Sunday August 30, 2015 @12:48PM (#10143784)
libclang is pretty amazing for that
Re:Show HN: Cdefs, extract function prototypes in C files to... by ncr100 on Sunday August 30, 2015 @04:14PM (#10144361)
Python libclang bindings make this kind of task quick work: https://github.com/llvm-mirror/clang/tree/master/bindings/py...
Re:Show HN: Cdefs, extract function prototypes in C files to... by sbt on Sunday August 30, 2015 @01:15PM (#10143874)
Came to see if this used LLVM for parsing, found node...
Re:Show HN: Cdefs, extract function prototypes in C files to... by theseoafs on Sunday August 30, 2015 @01:56PM (#10144005)
LLVM is not for parsing.
Re:Show HN: Cdefs, extract function prototypes in C files to... by moyix on Sunday August 30, 2015 @09:09PM (#10144960)
But clang can be.
Re:Show HN: Cdefs, extract function prototypes in C files to... by halayli on Sunday August 30, 2015 @10:07PM (#10145094)
clang is not a library.
Re:Show HN: Cdefs, extract function prototypes in C files to... by krunaldo on Monday August 31, 2015 @12:05AM (#10145377)
Re:Show HN: Cdefs, extract function prototypes in C files to... by ExpiredLink on Sunday August 30, 2015 @01:03PM (#10143829)
What's the use case for this?
Re:Show HN: Cdefs, extract function prototypes in C files to... by gnoway on Sunday August 30, 2015 @01:50PM (#10143992)
Seems like it must be to facilitate usage of whatever node's foreign function interface scheme is.
Re:Show HN: Cdefs, extract function prototypes in C files to... by megalodon on Sunday August 30, 2015 @02:02PM (#10144029)
The name is node-ffi and yes, you are correct. Can also be used for automated documentation purposes.
Re:Show HN: Cdefs, extract function prototypes in C files to... by eugenekolo2 on Sunday August 30, 2015 @08:40PM (#10144904)
I use something similar to generate API hooks for a large library.
Re:Show HN: Cdefs, extract function prototypes in C files to... by Matheus28 on Sunday August 30, 2015 @01:10PM (#10143856)
A mess of regexes and splits... yeah, no. You should probably get introduced to the wonderful world of parsers (and compilers):

https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniq...

Re:Show HN: Cdefs, extract function prototypes in C files to... by dang on Monday August 31, 2015 @01:32PM (#10147961)
Please don't be rudely dismissive of new work, even when it seems that someone doesn't know much. The Show HN guidelines specifically emphasize this: https://news.ycombinator.com/showhn.html.
Re:Show HN: Cdefs, extract function prototypes in C files to... by Matheus28 on Wednesday September 02, 2015 @03:14PM (#10161349)
Alright. Sorry, that might have sounded a bit rude, but the intention was pointing OP the right way.
Re:Show HN: Cdefs, extract function prototypes in C files to... by gnoway on Sunday August 30, 2015 @01:49PM (#10143987)
This is a bad name, another cproto library has been in use for over 20 years:

http://invisible-island.net/cproto/cproto.html

Re:Show HN: Cdefs, extract function prototypes in C files to... by megalodon on Sunday August 30, 2015 @02:29PM (#10144108)
You're right, that's kind of why I named the bash command 'proto' instead of 'cproto', but maybe that's not enough. Any suggestions? I'll change it later today.
Re:Show HN: Cdefs, extract function prototypes in C files to... by gnoway on Sunday August 30, 2015 @03:03PM (#10144186)
I should step back some from it being a bad name... It's actually a great name, it just conflicts with an in-use library that does substantially the same thing for another platform.

Is there a convention where the 'node-' prefix is off-limits for any reason? I don't know if it's really any better but if this were 'node-cproto' I wouldn't have commented.

The other option would be to do some word-play name like 'domesticator'.

Re:Show HN: Cdefs, extract function prototypes in C files to... by duaneb on Sunday August 30, 2015 @04:46PM (#10144447)
What happened to descriptive names like 'c2json'?
Re:Show HN: Cdefs, extract function prototypes in C files to... by gnoway on Sunday August 30, 2015 @05:11PM (#10144491)
Nothing, that is also a great name.
Re:Show HN: Cdefs, extract function prototypes in C files to... by duaneb on Sunday August 30, 2015 @04:46PM (#10144443)
I would recommend against using a generic greek prefix for a name of a very specific tool.