Are there any reliable solutions for annotations/reflection/code-metadata in C?

Not all languages support java-like annotations or C#-like attributes or code metadata in general, however that doesn’t mean it is not possible to have in languages that don’t have this.

An example is PHP with Stubbles and the Doctrine annotation library.

My question is, is there anything like this for C?, or are there any reliable ways of doing reflection with extended code metadata in C?

Ideally, I’m looking for something that reads javadoc-like comments.

Edit: The reason for me *needing* as opposed to just wanting, is that I need to generate C code and code-metadata from a database, as well as being able to edit that metadada and update the database. The volume of the work (~15,000 variables/structures/functions to generate from this database) justifies the solution.

7

The nearest thing I can think of is MetaC:

http://www.maier-komor.de/metac/

(Already mentioned by FrustratedWithFormsDesigner a few days ago)

Put aside this, there are a number of other systems based on the C preprocessor that can be used (or abused) for this task. Have a look at Boost.Preprocessor, for example:

http://www.boost.org/doc/libs/1_52_0/libs/preprocessor/doc/index.html

Or P99 and ABCPP:

http://p99.gforge.inria.fr/

http://code.google.com/p/abcpp/

Despite this, I strongly suggest you to use of some kind of full-blown code-generation tool for this task (as Brian already did).

All of the above-mentioned preprocessor-based tools, at the very end, are just convoluted ways to perform some kind of code generation. You could just implement your own full-blown, well-behaved code-generation tool instead. Ruby, Python and Perl offer a lot of good tools for this. For example, Ruby has its own Modelling and Code Generation framework:

http://ruby-gen.org/

http://rgen.rubyforge.org/

Many other exists for other scripting languages. You could even use a template engine normally used for developing web applications, like Cheetah (Python-based):

http://www.cheetahtemplate.org/

Have a look at the general-purpose Ruby-based WLang framework, as well:

https://www.ruby-toolbox.com/projects/wlang

Using a general-purpose scripting language and a code-generation framework, you will end up developing a real, stand-alone application that will query your DB and generate metadata and code accordingly. It can look like a big and complicated solution but it is actually easier to write and much more maintaineable than a preprocessor-based one (because a full-blown scripting language is much more powerful and flexible than the C preprocessor).

Moreover, from your “feature-requests list” I’m getting the feeling that none of the existing preprocessor-based tools can be used for your task “as is” because the C preprocessor cannot easily deal with a DB and because your task will most likely require a two-pass process (one pass for quering the DB and generate the required metadata and a second one for generating the C code from the metadata).

This can be another reason for using a full-blown scripting language.

2

Have you considered generating code??

Attributes and their associated behavior are just code if you could expand them. It would take a ton of setup but you’d have full control. If you’re generating this from a database, I think you have an extremely strong case–this is what ORMs do.

4

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật