Is there an library for C compiler which will add C++'s features?
Is there an library for C compiler which will add C++'s features?
Not really, since C++ is a different language. Some compilers (and the C99 standard) has cherry picked a few things that they find handy out of the C++ language (variable sized arrays and "variable declarations anywhere" being the most obvious ones).
On the one hand, you could say that all C++ features can actualy be achieved in C. On the other hand, C++ _IS_ a different language, and to add those features to C would require changing the compiler - you can't just use a library as replacement.
But bear in mind that the first C++ compiler actually produced C code, and used a standard C compiler to generate machine code.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I don't know of such a library, but if you need to implement an object orientated design in C, then there are different strategies for this. Some links that might be useful:
ldeniau.web.cern.ch/ldeniau/html/oopc/oopc.html
www.planetpdf.com/codecuts/pdfs/ooc.pdf
www.bolthole.com/OO-C-programming.html
>>Not really, since C++ is a different language. Some compilers (and the C99 standard) has cherry picked a few things that they find handy out of the C++ language (variable sized arrays and "variable declarations anywhere" being the most obvious ones).
When did C++ get variable sized arrays?
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
You can do that in C99, so it's not really a C++ feature
Ooops my bad . Sorry matsp.
Sorry, C++ doesn't technically support that, but gcc does as an extension - I got myself confused [again]. I'm not sure if C99 does support it or not - gcc -std=c99 -pedantic does compile this:
whilst g++ -std=c++98 -pedantic does not. Remove pedantic and it does.Code:#include <stdio.h> double func(const int n) { int arr[n]; double d = 0; for(int i = 0; i < n; i++) { arr[i] = 1 << i; } for(int j = 0; j < n; j++) { d += 1.0 / arr[j]; } return d; } int main() { int n; printf("Enter number of elements:"); scanf("%d", &n); printf("Result=%f\n", func(n)); return 0; }
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
VLAs were a GCC extension and were adopted in C99. They're not part of any C++ standard, and won't be part of C++0x, AFAIK.
GCC's documentation says, however, that their implementation of VLAs is not 100% compliant with the C99 definition.
http://gcc.gnu.org/c99status.html
A good library for getting object-oriented functionality into C is glib/gobject.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Yes, that's the whole point asking here.
A library I am using compiles only with a C compiler, but not with a C++ compiler. My platform and compiler is outdated. Also no C++ compiler available with full (compared to recently compilers) standard support.
C++ as "addon" for a standard C compiler would have been a nice thing, but if it doesn't exists I am out of luck.
That would be quite impossible. Different syntax means the compiler itself must change.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
I'm not sure if I understand your problem well, but you can mix C and C++ code. In short you compile your C code with the C compiler and C++ code with the C++ compiler. By supplying linkage specifications you're able to use C code within C++ code.