pure c support/util library - c

I am searching a library in C/pragma/.. for basic programming tasks.
Something for handling and creating Lists and hasmaps and arrays and souch stuff.
So i dont have to reinvent the wheel again and again and write the same structures again and again.
But has to be pure C library.
Thanks for any help.

You might want to retag your question and remove the C++ tag, as your question is a little strange with the tag.
If you need something implemented in C, then look at Glib, which is part of GTK+, and it implements data structures like linked lists and trees.
Alternatively, the Apache Portable Runtime is a project from Apache which is also written in C, and is used in the Apache web server.

In plain c projects I tend to use the APR.
Maybe it covers all the things you need. And it provides a nice abstraction of the OS too.

Glib

In addition to the other answers, you might take a look at the source code accompanying the book C Interfaces and Implentations.

Related

Is it practical to use #ifdef's to compile a library without certain features?

So I'm currently working with a proprietary programming language that is C-like. So while this question wasn't directly inspired by a C program, I think those of you who are familiar with C may be able to offer some good insight.
I'm currently working on a library. This library encompasses some basic features as well as features that require other libraries. I'm running into the problem of 'where do I draw the line for how many dependencies are included in this library?'.
So this seems like it could be a fairly common problem. What methods exist for addressing this issue?
Something I've had in mind. Implement #defines and #ifdefs that allow users to compile the library with only the features they want. So essentially, all of the library functions that require additional libraries would be wrapped in #ifdef guards. The user would be responsible for #define'ing the features they want. Essentially, this method would allow a user to still use parts of the library without needing to have other dependent libraries.
Your thoughts? Again, this is for a C-like language. Thus tools like CMake, etc. aren't available.
Yes. If you take a look at the Linux kernel for instance, it's done the exact same way.
Yes you can and You Should.
I use them whenever i feel the necessity. Also, i have been working on freeRTOS and that's how things are being done over there.

Making a GUI simulator in C

Hello StackOverflow Community,
I am writing a MicroMouse Simulator in C language. And I wanted something to visualize the way the maze is being solved like this -- http://www.youtube.com/watch?v=N9TkDgJNJso
I've been researching a way to accomplish this, but I haven't found anything with enough documentation to accomplish my goal.
I don't want to implement this using ASCII symbols, to me it doesn't look professional.
Is there any good GUI interfaces that I could use in C to help me accomplish this? And if so, how would I use it? I don't mind having to code in another language like Java or Python to accomplish my goal.
I saw the video that you want to make. After watching the video I feel you don't need a GUI library for this simulator program.
Here is a list of libraries that you can use.
1.OpenGL This is a 3D graphics API which also can be used for 2D and can be used with both c/c++
2.SDL This library is easy to understand for a beginner. For your program this library is better and can be used with both c/c++.
3.winBGIm This is same as the graphics.h that you found and can be used both c/c++ but it is only for windows.
If you are looking for GUI library then here's a short list.
1.GTK This is written in c and is a popular GUI library for c. You can find a GUI editor for gtk forms called glade which enables quick & easy development of user interfaces.
2.WxWidgets This is written in c++ so you have to use c++ rather than c.
3.FLTK
There are many more libraries besides these which you can find in google. You said
I do not mind having to code in another language like Java or Python to accomplish my goal.
Then for java you can use swing and If you are windows developer then use the windows form application in visual c++; then development of your program will be very easy.
SDL is one of candidate for C in order to make GUI Simulation. Lazyfoo is one of the best site I found for beginner.
SDL is strongly portable. It's written in C and there're a lot of documentation and tutorials.

Template based C / C++ code generation

Any suggestion for template base code generator for C / C++ specifically to generate repetitive code generation? (Not UML / MATLAB model based or other advanced stuff). For a newbie in this field any good generic tutorial (not tool based)?
I came across GNU Autogen looks good but looks like it needs a steep learning curve. I would prefer some plug-in for eclipse like IDE, easy to use and most importantly good tutorials.
The basic concept of code generation is simple enough - and people's needs are varied enough - that there are quite a few options out there.
Boost.Preprocessor is a library of functions built on top of the standard C / C++ preprocessor that makes it much easier to use the preprocessor to do code generation. It's not as flexible as other options, and figuring out preprocessor errors can be tricky, but the fact that it uses only standard language features greatly simplifies using it and integrating it into your builds.
If you know Python, there's Cog.
Some of Google's projects use Pump.
There are many general-purpose templating solutions (Python's Genshi, eRuby, etc.). These are often designed for generating HTML and XML but also work for code.
It's also easy enough to hack something together in the scripting language of your choice.
Without knowing more about what your needs are and what tools you're comfortable with, I can't give a more specific recommendation.
I'm not familiar with anything that provides an Eclipse plugin.
If you know Python, then Cog could be considered as light-weight solution: http://www.python.org/about/success/cog/
Look at my answer for a similar question for Java classes using M2T-JET, an eclipse based, lightweight templating generator. JET is language agnostic and you can see from the example that it's fairly easy to use.
I appreciate using Lua for this task, with something like Templet or one of another myriad of Lua-based preprocessors. The benefit of using Lua over something like Python is that you can, if necessary, include the source code to your template processor and a basic Lua installation along with whatever it is you are shipping. You may then add the compilation of Lua and subsequent template files to the build process as usual.
I would advise not using Python-based solutions for one reason: juggling various pythons to satisfy every developer's use of a completely different yet incompatible version is annoying. If you choose to use a language which you can't embed in your trees, you'll want to make sure pre-computed versions are available.
Late to the party but I would recommend Codeworker Its the only tool I found that does everything the above tools do and more. It has the Python Cog like functionality for embedded generation, it has the template based generation like Templet or Pump. And it has the rather useful feature of protected areas so you can customise your code as needed and re-generate.
I have used it for generating all the boiler plate c++ code as well as configuration for projects like SQL, config, javascript etc.

Methods for organizing/showing algorithm that is coded in C or MATLAB

Is there any recommendations for how to show what your code is doing (C or MATLAB)? Imagine if your code is really long and you have a lot of functions in your program, what is the best way to document the program? I know Java IDEs have a way to ingest comments and spit them back out into a document that shows all the functions, and their inputs and outputs. I don't think C or MATLAB has this feature. At this point, I am thinking comments are the only way to show what is going on in the code, but it may confuse the reader if they have to look through the raw code along side the comments. The second option would be to write out the algorithm in a text editor such as Microsoft Word. Is there an industry standard for doing this?
Thanks!
What Java uses is JavaDoc.
For C, you can use Doxygen.
I also saw this which suggests you can use Doxygen with matlab too!
The mother of all literate programming is http://www-cs-faculty.stanford.edu/~uno/cweb.html
cweb. The father is Knuth.
Recent versions of MATLAB actually do have some features very similar to this. If you implement your MATLAB code in object-oriented classes, MATLAB will auto-generate documentation for you by just typing doc myClassName - it's really quite similar to Doxygen. If you're not using object-oriented code, you can use MATLAB publishing to generate a document from your scripts and functions.
Doxygen's C support is quite good. It supports JavaDoc style and Qt style markup comments, as well as some additional features. See the manual for examples of what the markup looks like. I don't have an example of the output ready to hand, but it's quite customizable.
The Octave project, which implements a language and environment that's effectively a superset Matlab's, uses texinfo to document its functions. You can see an example of the markup in the Documentation Tips section of the manual. I recommend scrolling to the bottom of the page to view a complete markup example rather than reading the lengthy explanation that precedes it. I have little experience with texinfo beyond using help from within Octave, but I believe the online manual was generated from texinfo sources, so it seems sufficiently capable.

Tips on wrapping a C library in Objective-C

I have a library written in C that I would like to use in an Objective-C app, either on the Mac or the iPhone.
Unfortunately, since this library is being written by individuals in the open source space, the documentation is quite sparse and incomplete. While I can figure out how to use the stuff in the library, I don't really have an overview of the entire code base.
What I would like to do is wrap the library up into some easily usable and transferrable classes in Objective-C.
Does anyone have any tips on how to approach this?
Any advice on the best way to get a visual hierarchy of how the library is structured?
How would I go about deciding how to best structure the wrapper for reusability and ease of use?
Any and all help will be greatly appreciated, thanks!
I've done this a few times myself. This can be fun -- it's your chance to fix (or at least hide) bad code!
You can use Doxygen to get a visual hierarchy of the code (although I've only used it for C++ libraries, it also works with C), or any of the other free tools out there.
Don't structure your wrapper class like the underlying library if the library isn't designed or documented well. This is your chance to consider the point of view of the user and how they are going to be using the code. Write your test cases first to figure that out, and/or talk to some people who use the library already.
Two nice design patterns that match up with what you're doing are Adapter and Facade.
First, remember: a C library is an Objective-C library. You don't actually need to do any wrapping at all, although you may want to if the library interface is especially cumbersome.
Second, if you decide that you want to write a library wrapper, keep it simple. Identify the core functions of the library that you actually plan to use, and think about how best to provide an interface to those functions and those functions only, with your intended usage in mind. Design an interface that you want to work with, then implement it over the library.
Since ARC (Automatic Reference Counting) was added to the Apple compilers and libraries, Objective-C and C are no longer so freely interchangeable. (Here's a list of ARC documentation and tutorials.) You need to consider the memory allocation issues much more thoroughly, and you might just want to "bridge" the libraries. See this SO question and some of the links from there, about how Apple bridges between Obj-C and C libraries.

Resources