Maybe it's a dumb question but:
I'm looking for a library for the classic functions on arrays of Integers (sorting, searching ...) in C, does anyone know a good one ?
I could rewrite those functions but, to be honest, I'm quite lazy.
More generally, is there a list of known libraries somewhere?
Thanks in advance
Related
The C compiler was written in C, that much I know. What language/tools/instructions was/were used to create the initial functionality for the C compiler to become self-hosting?
UPDATE:
I know what bootstrapping a language is, and it is that research that prompted this question. I cannot find an answer to my question anywhere on SO.
There are a multitude of C compilers in the world. Many of them were (and still are) written in C. However the first one was not - it was written in B.
I've seen several implementations of recursive descent c interpreters which all seem
to do a pretty good job - yet they all only implement a small portion of the C language -
for example they don't support structs or typedefs etc -
Does anyone know of any code that supports a large portion of the C language.
I know adding more functionality would be pretty trivial - but I'm a bit strapped
for time.
Picoc supports more that most of the Tiny/Small C interpreters. You might give it a look. And it does support structures.
If you just want to use it, this one looks awfully good for the job. There was a Dr. Dobb's article on it a while back ... there it is
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Representing dynamic typing in C
A professor at my History of Computation side-lecture went into great depth about manifestly typed or type-inferred languages and generally praised the greatness of latently typed languages (faster dev times, dynamic systems, etc...).
The same day, at an Automata Class, another prof says:
Dynamic typing makes things more complex by adding more ways to do the same thing.
I've been using statically typed languages most of my life : C/C++/Java - my only exposure to the other has been Shell Coding and Ren'Py.
My question is, can I write a simple program in C that implements some of the benefits of both ?
For instance, I could create Unions to accept all user driven data, like so :
typedef union {
int int_type;
char char_type;
//and so on
} dynamic;
// Var Creation :
dynamic data;
// For unknown return type
void* function(dynamic data);
I realize a Union could compromise type-safety, but that is what I'm trying to do here. What other approach could I take ? I'm just trying for a demonstration.
I tried for an answer from this question. But honestly, I could not follow the arguments closely.
I apologize if the question seems silly.
PS
Using suggestions from below, I wrote this : http://codepad.org/A9JAX8lD, which basically does nothing much dynamic, but is at least a start.
I think I see what both my professors were trying to say.
My suggestion is not to try doing dynamic typing in a statically typed language. It will most likely have sub-par performance and a very strong syntactical burden. Instead, if you only ever have experienced statically typed languages, I would strongly suggest trying out Python. It is highly dynamic and will teach you new ways of thinking.
And last but not least, there also is Cython which is a Python dialect using C as intermediate language. It can mix static typing and dynamic typing, it's really refreshing.
I'm not against types, but I don't know of any type systems that aren't a complete pain [...]
-- Alan Kay
It's quite possible to implement a fully-featured dynamic type system on top of C: Take GType, on which the GLib Object System is based.
However, such systems are often painful to use because of the amount of boilerplate code they need, which can be worked around by using custom code generators and preprocessors, which is how Objective-C got started.
If you want to show how C can be "not type safe" try using void* to pass arguments. The downside is that it's not truly dynamic since you cannot call any methods on the object without casting it first.
I looked all over the internet and I can't seem to find one.
There is something similar in Java, but I need to use C (preferably something I can use locally). Has anyone got any ideas?
Copy of my answer:
If you need to do operations with HUGE decimal values I would suggest you to use http://gmplib.org/ library. I've used it a lot with C and C++.
At the risk of oversimplifying something I'm worried might be ridiculously complex, what should I be aware of when mixing C and Objective-C?
Edit: Just to clarify, I've never worked with C before, and I'm learning Objective-C through Cocoa. Also I'm using the Chipmunk Dynamics engine, which is C.
I'd put it the other way around: you might be risking overcomplicating something that is ridiculously simple :-)
Ok, I'm being a bit glib. As others are pointing out, Objective-C is really just a minimal set of language extensions to C. When you are writing Objective-C code, you are actually writing C. You can even access the internal machinations of the Objective-C runtime support using some handy C functions that are part of the language (no... I don't recommend you actually DO this unless you really know what you're doing).
About the only time I've ever had mildly tricky moments is when I wanted to pass an Objective-C instance method as a callback to a C function. Say, for example, I'm using a pure-C cross platform library that has functions which accept a callback. I might call the function from within an object instance to process some data, and then want that C function to call my instance BACK when its done, or as part of getting additional input etc etc (a common paradigm in C). This can be done with funky function wrapping, and some other creative methods I've seen, and if you ever need to do it googling "objective-c method for c callback" or something like that will give you the goods.
The only other word of advice is to make sure your objects appropriately manage any manually malloced memory that they create for use by C functions. You'll want your objective-c classes to tidy up that memory on dealloc if, indeed, it is finished.
Other than that, dust off any reference on C and have fun!
You can't 'mix' C and Objective-C: Objective-C is a superset of C.
Now, C++ and Objective-C on the other hand...
Objective C is a superset of C, so it shouldn't conflict.
Except that, as pointed here pure C has different conventions (obviously, since there is no built-in mechanism) to handle OO programming. In C, an object is simply a (struct *) with function pointers.