J
jxh
Why use this horrible syntax ?
As stated in the quoted material, it is for compatibility with
C++, but also to lessen the burden of introducing the feature
into C compilers.
-- James
Why use this horrible syntax ?
jxh said:As stated in the quoted material, it is for compatibility with
C++, but also to lessen the burden of introducing the feature
into C compilers.
I guess you are refering to environments providing tightly cooperating
C++ and C compilers.
That's what some people call C/C++ compilers, but I don't like the latter
term as it gives the wrong feeling that C/C++ is a language.
In data Sun, 7 Oct 2007 09:15:04 +0100, Malcolm McLean scrisse:
in how i see the thing (don't know if compiler follow me)
in ("123"+"457") + ("123"+"456")
first there is
tm1=("123"+"457") , tm1=("123"+"456")
than
return tm1+tm1
so if there is only one golbal variable "tm1" for doing the sum
at the end there will be a wrong result
but with one only variable tm1 all is ok with
"123"+"457" + "123" + "456";
because it is ((("123"+"457") + "123") + "456");
tm1=("123"+"457");
tm1+="123";
tm1+="456";
return tm1;
user923005 said:It would be really nice if C could adopt a really nice algorithms
library like C++'s STL + BOOST.
André Gillibert said:And size_t which can be larger than unsigned long or ptrdiff_t which can
be larger than long.
Keith said:... jacob has argued against C++-style destructors
because they're difficult to implement; the point is to make the
compiler, rather than the programmer, do that hard work.
One of the most important differences between C and many other
languages, including C+++Boost, is that C does not believe the marketing
line that "One size fits all". This is a Good Thing. It would be nicest
if it stayed that way.
A part of C did escape, then it morphed into C++....user923005 said:Do you honestly believe that having a huge, debugged, efficient
toolkit at your disposal is a *detraction*?
That's really weird (to me).
I can think of literally zero drawbacks from having the STL and BOOST
at your disposal in C++.
They are supremely well documented and very well engineered.
It turns out that it would be very hard (because of the lack of
generic programming fascilities) to produce the same thing in C.
This means that C is relegated to a niche that it could otherwise
escape if it had the same tools available.
Ian said:A part of C did escape, then it morphed into C++....
It's a psychological rule. As are all the ten rules of programming.Richard Heathfield said:Chris Thomasson said:
Practically, there is no "rule of two" anyway. It's just something that
Malcolm has made up. A "rule of two" assumes that the number two not only
exists but is a significant and therefore reasonable number.
Malcolm McLean said:It's a psychological rule. As are all the ten rules of programming.
Shouldn't there only be two rules of programming?
Note I'm not proposing the addition, it's just that RAII is
the one thing I miss most when swapping from C++ to C. Just
about everything else can be worked around in standard C. The
closest equivalent I know of is pthreads cleanup handlers.
Maybe something along those lines might be a more acceptable
extension to C?
user923005 said:Do you honestly believe that having a huge, debugged, efficient
toolkit at your disposal is a *detraction*?
I never used the word detraction, and I don't see what it
would detract from. I _do_ see that C is mostly a systems
language, not a bells-and- whistles already-slow application
language. Because of that, many C programmers will want to use
ADTs which have been tuned to their application, and not a
one-size-fits-all solution which does in fact _not_ fit 90% of
all cases very well.
jxh said:For a different example, a template function based quick sort
implementation could allow the compiler to inline the call to the
comparison function.
/* generic_qsort.c */
PREFIX(qsort)(TYPE *arr, size_t len) {
...
if (LESS(*right, pivot)) {...}
...
}
/* int_qsort.c */
#define PREFIX(s) int_##s
typedef int TYPE;
static inline int LESS(int a, int b) {return a < b;}
#include "generic_qsort.c"
#undef PREFIX
not much longer than c++ templates imho
macros are ugly though
/* generic_qsort.c */
PREFIX(qsort)(TYPE *arr, size_t len) {
...
if (LESS(*right, pivot)) {...}
...
}
/* int_qsort.c */
#define PREFIX(s) int_##s
typedef int TYPE;
static inline int LESS(int a, int b) {return a < b;}
#include "generic_qsort.c"
#undef PREFIX
not much longer than c++ templates imho
macros are ugly though
Interesting , Mr "user923005". So you are Heathfield. It seemed to meuser923005 said:I used this very technique in the source code for chapter 13 of "C
Unleashed".
I called it PRELUDE instead of PREFIX.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.