This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Are there any open source C libraries with common data structures?
What is the best source of algorithm and data structure implementations for C programmers? Links to an open source library or a book will do. (Please don't point to Sedgewick, as I already have his book).
Though I have not used GDSL ( Generic Data Structures Library ) I think it's worth considering as it implements many frequently used data structures.
The Algorithm Design Manual by Steven Skiena
(source: alberton.info)
Another C library worth checking out, especially because it hasn't been mentioned in answers to this question and also the other duplicate questions:
the C Algorithms Library, it can be found at http://c-algorithms.sourceforge.net/ and is covered by a BSD-style license, i.e. it can be freely used in any project. I've used it myself in several smaller programs without encountering any problems.
Art of Computer Programming, Volume 1: Fundamental Algorithms (3rd Edition)
http://en.wikipedia.org/wiki/The_Art_of_Computer_Programming
Related
This question already has answers here:
What are the barriers to understanding pointers and what can be done to overcome them? [closed]
(28 answers)
Closed 5 years ago.
I am learning c language for over a year now. But I still don't understand how pointers work. Can anyone suggest a good online resource to make concepts clear.
There is vast number of sources regarding C pointers. You can google for it. Try to read a few, one of them may just click.
Here just few which I like:
https://boredzo.org/pointers/
https://en.wikibooks.org/wiki/C_Programming/Pointers_and_arrays
https://users.cs.cf.ac.uk/Dave.Marshall/C/node10.html
https://en.wikipedia.org/wiki/Pointer_(computer_programming)
https://www.geeksforgeeks.org/function-pointer-in-c/
If you are clear with your concepts of pointers in one language, it would mean that you are clear in all possible programming languages as it is one of the most fundamental concepts.
Geeks for Geeks : More reliable source to clear basic concepts
https://www.geeksforgeeks.org/pointers-in-c-and-c-set-1-introduction-arithmetic-and-array/
Hackerrank is a good source for practical knowledge
https://www.hackerrank.com/challenges/c-tutorial-pointer/problem
Tutorials Point is yet another saviour
https://www.tutorialspoint.com/cprogramming/c_pointers.htm
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
It might be a silly question, but I'm interested in it very much. Is it possible to implement operator new, dynamically expanding arrays, classes in pure C?
Any links or code examples will be appreciated.
new: #define new(type) malloc(sizeof(type)) (have to call it using function syntax, like struct stat *st = new(struct stat))
dynamically expanding arrays: realloc plus some custom array-manipulation functions (like push_back, etc.) - this is commonly implemented by third-party C utility libraries (and, as #Mgetz points out, some compilers have built-in extensions for it)
classes: structs with function pointer members (this is very common in several projects, such as the Linux kernel)
You might want to look at GObject, which is a C library providing some object-oriented features to C. Also see the dozens of hits you get for googling "Object-Oriented C".
A quick google search revealed this:
http://ooc-coding.sourceforge.net/
Haven't read it through but it sounds like what you're after.
Yes, it is possible (common?) to implement object orientedness in C - or at least the bits that are especially needed.
An example is a once created a garbage collector by storing the pointers to malloced memory and the free function in linked lists.
The best thing about C is that it just works and there is almost zero overhead. The more work a language does for you automatically can mean there is a lot more overhead - though this is not always the case.
It depends if it is OK for you to reimplement the compiler.
If it's ok - you can do whatever you wish, otherwise:
new - as an operator - no, but you can define a function + macros that will simulate it.
classes - yep, you can. you may simulate it pretty closely with static functions and an array of pointers to functions. But there will be no overloading.
expanding arrays - yes, with the classes simulation above.
This question already has answers here:
Are there any solid large integer implementations in C? [closed]
(7 answers)
Closed 8 years ago.
Recently in programming contest in Here, the problem is pretty straight forward but catch is with worst case scenario which we have to handle data of size 10^10000 .
I tried the program in python which is straight forward as i don't have to specify the datatype(It is taken care by the compiler ) but when i tried with C I couldn't find the correct datatype .
(I tried uintmax_t which didn't work out too).
So how to approach very huge type of data's in C ?
There is no built-in datatype in C that can store that big values. You will either have to write your own implementation or use a library. As this is a competition, though the second is not an option. Every now and then similar problems appear and usually the best approach is to use another language e.g. java(as it is usually available on competitions).
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I am working on a project where I need to crunch large integers (like 3^361) with absolute precision and as much speed as possible. C is the fastest language I am familiar with, so I am trying to code my solution in that language.
The problem is that I have not been able to find a good implementation of any data types for representing limitless integers in C other than Python's source code. It is taking me time to go through the code and determine what I need.
I would much rather use someone else's tested code with a full set of functionality (addition, subtraction, multiplication, division, modulation, exponentiation, equality checking... even bitwise operation would be sweet) than spending the weeks it would take me to even begin to get my own version up to par. While it would be a great learning experience, it is not the focus of my problem, and I'd rather get to the part that interests me :)
A couple of people have already mentioned GMP. I would only add that at least the last time I looked, it was pretty well restricted to working with gcc.
If you want to use other compilers, are couple you might consider are NTL and MIRACL. I've tested MIRACL a bit, and it seems to work reasonably well. I've used NTL quite a bit more, and while large integers are more of a sideline for it, it still does them quite nicely. It doesn't claim to be as fast as GMP (and, in fact, can use GMP to do basic operations), but when I've done some minimal benchmarking between the two I haven't found a lot of significant differences (though that was long enough ago that I doubt it's valid anymore either).
Gnu MP provides a bignum library.
The OpenSSL library also provides a solid BigNum implementation (<openssl/bn.h>).
I use MAPM which is a portable arbitrary precision (integer and floating point) library.
libtommath, from libtomcrypt, is probably the smallest, simplest, and fastest. (Funny how those 3 superlatives almost always come together...) If you can't find an upstream you can get the source from the dropbear ssh source tree.
If you want ANSI Standard C, get the code in Dave Hanson's C Interfaces and Implementations. Very clear and well designed.
If gcc and gcc extensions are OK, then as others have pointed out the Gnu Multiprecision Library (GMP) is well thought of and widely used.
Mbed has a bignum implementation that serves as basis for the crypto functions.
It is heavily used on microcontrollers.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Does anyone know any good resources with tasks or problems to get practice in things that are "new" in C from the point of view of someone with experience in high-level languages like C# and PHP? All I can seem to find are more "challenges" than problems for practice.
Thanks.
K & R. [Kernighan & Ritchie]
http://www.amazon.com/Programming-Language-Prentice-Hall-Software/dp/0131103628/ref=pd_bbs_1?ie=UTF8&s=books&qid=1240539543&sr=8-1
You could try Thinking in C by Bruce Eckel.
It is completely free of charge, and is available for download from his website.
As others have said, read K&R.
Pay special attention to pointers, structs, unions, bit fields, typedefs, and the C preprocessor. Pointers and pointer arithmetic are very important.
Read the C preprocessor manual.
Learn to write makefiles. Read the manual for your version of make.
K&R is outdated.
I prefer C Primer Plus 5th Ed by Stephen Prata
ISBN: 0-672-32696-5
It covers C99.
This supposed to be C bible.
Problem Solving and Program Design in C
by
Jeri R. Hanly, Elliot B. Koffmon and Frank L. Friedman
Check out The Standard C Library by P. J. Plauger, from 1991. It alternates quotes from the standard (C89, I believe) with discussion of how the library functions were intended to be used, along with a fully described implementation of the complete C standard library. Source code is included as well.
Yes, the book hasn't been updated for the latest standard, but it still has a lot of value from explaining at least some of the rationale behind some of the oddities of the standard library. Incidentally, Plauger was on the standards committee.
Plauger wrote a number of the classic books on both C and early Unix. Track down and read the oldest for a taste of pre-C history...
Given your previous (C#) programming experience I guess you don't need a book that teaches how to program but the intricacies and subtleties of C. I'd recommend the following:
Prentice Hall - The ANSI C Programming Language 2nd ed. by Brian W. Kernighan and Dennis M. Ritchie. For basic questions.
Prentice Hall - Expert C Programming. Deep C Secrets.
ISO - C 99 Standard - final. Very useful for many doubts and questions
A source of problems to solve that have known answers is Project Euler.
It isn't itself C specific since there is a decidedly mathematical orientation to the problems as presented. However, making an honest attempt to solve a significant number of them would require a growing proficiency with structures, pointers, the standard library, and thinking about things in ways that work well in C.
Another resource that often seems to be overlooked is that MIT has been putting a large percentage of their curriculum online. Their EE/CS department is no exception.
The class Introduction to Algorithms might be one suitable choice. The textbook is Introduction to Algorithms, Second Edition, by Cormen, Leiserson, Rivest, and Stein which is reasonably well written as text books go. I didn't exhaustively search the course list, so I'm sure there are other gems in there as well.