Only in that it lacks some niceties that more modern languages (like
Perl, or Java, or C#) provide, such as exceptions.
No *you* don't. The people who wrote the library you use *do*.
Yes, you do. The libraries that make allocation and deallocation and
buffer sizes so transparent that you never need worry about them... are
very rare indeed. I have rarely coded in C where I didn't have to worry
about such issues.
So you take a library. I have never seen a language doing thinking for
me.
I'm not asking the language to do the thinking for me. I'm asking it to
do some of the grunt-work for me.
For example: You're writing a library function, which writes to a
buffer provided by the caller. The caller will typically allocate a
string (say), either on the stack or dynamically via malloc, and pass it
to your function. Wouldn't it be nice if your function could determine
how large the buffer was, so it could prevent an overrun?
In C, that's traditionally the responsibility of the top-level
caller, which means that every C programmer *does* have to worry about
allocation and buffer sizes.
C control structures:
function calls.
if/else
while
for
do...while
switch
goto
C control overrides:
return
break
continue
C's loops are unlabeled, meaning that you can only break or continue out
of the innermost one. Perl (and I think C#) allow you to break out of
more than one level at a time.
C has no exception mechanism.
C permits at most only one return value from a subroutine (of course,
this return value can be a structure).
C gives no information about the number or types of arguments passed to a
subroutine, or any information about the caller.
How come? I could make heterogeneous structures in C, quite easily even.
Are they removed from C++?
Not without copious "void *" and casting, you can't.
How is it worse in C/C++ (or Java)?
Strings auto-extend in Perl. You cannot overrun a buffer in Perl.
Perl makes it a breeze to join strings, split them, interpolate variables
into them, perform pattern matching and replacement upon them, have
multi-line strings, read them from files, I could go on and on.
You can _do_ all of these things in C or C++, but the equivalent code is
longer and more tedious.
C++ is the classic "B&D" OO language. Everything must be tied down at
compile time. You have to dance with templates to get any sort of
generic data structures, and even then you have to work hard.
In Perl, you can have one class manufacture objects of another class, you
can add methods at run-time as needed, you can handle any unknown methods
via AUTOLOAD, you can tell who called you, and with what arguments, you
can examine your own hierarchy, etc. Perl provides closures; neither C
nor C++ have anything like those.
In Perl, you can write a function:
sub add_args
{
my ($arg1, $arg2) = @_;
unless (UNIVERSAL::can($arg1, 'add')) {
die "Can't add $arg1 and $arg2";
}
return $arg1->add($arg2);
}
and it will add any arguments, of any type, whether declared at compile-
time or not. The only major deficiency there is that it won't add any
built-in types. Writing such a universal function in C++ is pretty much
impossible.
Compared to C or C++? Yep.
--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`