free() function translated into C# equivalent - commentsappreciated...

J

James Kuyper

Richard said:
Ike Naar said:


What is a Teletubbie?

<OT>
A TV show that is targeted at audiences as young as 1 year old, with
correspondingly little plot, dialog, or much of anything else that you
would normally consider essential to watchable TV. The relevant feature
of the Teletubbies is that their speech is very similar to the speech of
the target audience.

According to <http://en.wikipedia.org/wiki/Teletubbie>, it came from
your country, so if you've never heard of it you probably haven't
recently been involved with children young enough to be in the target
audience.
</OT>
 
J

James Kuyper

Ike said:
You regularly frown upon the use of sms lingo in this forum (and you
have a valid point in doing so).

Just for your information (no offense intended): to a non-native
English speaking person like me, phrases like ``i m'', ``u r'' and
``plz'' are uneasy on the eye, but at least they do make sense.
While ``Duh!'' or ``D'oh!'' mean as much to me as ``aouw meuk!''
would mean to you.

<OT> Well, it's been in the "New Oxford Dictionary of English" since
1998, and in the "Oxford English Dictionary" since 2001.</OT>
 
A

Antoninus Twink

Thanks, James.

Addition of "Teletubbies" to approved list of topics on clc noted.
My kids are nearly all growed up now,

English /is/ your first language, isn't it Heathfield?
but since we haven't watched TV for many years they wouldn't have seen
it anyway.

How silly of James to forget that you're a Christian fundamentalist who
thinks that the TV is an instrument of the devil! Do you let your wife
wear trousers, Heathfield?
 
K

Kojak

Le Fri, 27 Feb 2009 07:24:06 -0600,
blargg a écrit :
I think it's appropriate for a momentary interjection of the poster's
more full personality, to make a small human connection, to succintly
get something across (though this apparently failed due to it being a
regional term). It's not appropriate within the technical content of
a message, for sure.

D'oh!

All this sub-thread just for a small and funny interjection ? D'oh!

:)
 
K

Kaz Kylheku

Han said:
The OP should bear in mind that the above statement is one of those
dogmatic, religious statements on comp.lang.c. To be sure, it's a true
statement as it stands, but the devil is in the details.

The only thing you can take away is that "the cast is unnecessary". That's
it. But keep in mind that most whitespace in C code is also unnecessary.
So it's up to you whether you want to use the cast as a matter of style.
[...]

Unnecessary whitespace doesn't cause the compiler to be less-restrictive
about the code it accepts, while unnecessary casts do.
A cast reduces
restrictions placed on the expression being cast.

That is generally true, but not in this case.

A (type *) cast added to a void * expression increases the restriction,
because unlike the original expression, the augmented expression now no longer
be assigned to an lvalue of arbitrary pointer-to-object type.
So if you put a cast and
then put the wrong expression on the right, or the expression later gets

That would be the case if the void * type hole did not exist.

But the hole being what it is you have to consider this case:

If you put a void * on the right, and there is no cast, you can put a pointer
to any object type on the left, with no diagnostic.

The behavior of void * in C is as if it automatically generated a cast
to the left hand side! If you add your own cast, then you plug this
behavior by forcing a particular type.

// hole in type system:
A a_obj;
A *a = &a_obj;
void *v = a;
B *b = v; // pun!
C *c = v; // pun!
D *d = v; // pun!
changed to be wrong, you're less-likely to have that diagnosed by the
compiler. Thus, you should cast only when necessary.

That's good advice---in a language which doesn't have a type hole that allows
an unsafe conversion! Because in that language, the pointer conversion
situations in which casts are unnecessary are type-safe, and do not require the
documentation of a cast.

The advice needs to have an exception: don't write casts that are not required,
except in situations where the lack of a requirement for a cast is a gaping
hole in the type system!
This is one reason
C++ provides several less-powerful casts, so that one can avoid turning
off so many restrictions, as a C-style cast does.

Note that those less powerful casts are a refinement which came years after C++
banished the implicit conversion from void *.

This is a situation where a diagnostic /should/ be necessary. And that's
the rationale for writing the cast anyway.

The reason that diagnostic is required in a conversion is to alert the
programmers to change the code somehow, or just add a cast if the conversion
looks safe.

The cast, should it be added, is then a visible record in the program text
which makes it obvious that a suspicious conversion is going on.

If you don't ever write casts which are not necessary, but the language has
holes that allow for unsafe conversions without casts, then you may end up with
places in the program where unsafe conversions are occuring inconspicuously.

Let me pose this question to you: suppose that C simply allowed all pointer
conversions to be written, regardless of type, without any diagnostics being
required. Would you then write (A *) to (B *) conversions without a cast, just
because it's unecessary?
 
K

Kenny McCormack

Kojak said:
D'oh!

All this sub-thread just for a small and funny interjection ? D'oh!

The point is the hypocrisy. That if a newbie uses what may be the only
dialect of English that he knows, the regs will jump all over him in
self-righteousness. But there is obviously a different law for the
regs. If they use a bit of American pop culture in their posts,
everyone is supposed to think it adorable.

As I said elsewhere (and will continue to point out as needed), the
"anti-SMS" is just thinly veiled racism.
 
R

Richard Tobin

Unnecessary whitespace doesn't cause the compiler to be less-restrictive
about the code it accepts, while unnecessary casts do.
A cast reduces
restrictions placed on the expression being cast.
[/QUOTE]
That is generally true, but not in this case.

A (type *) cast added to a void * expression increases the restriction,
because unlike the original expression, the augmented expression now no longer
be assigned to an lvalue of arbitrary pointer-to-object type.

But in this case the error that's masked (in poor quality compilers)
is that the expression being cast is not, in fact, a void *
expression, so this is irrelevant.

-- Richard
 
R

Richard

Richard Heathfield said:
James Kuyper said:


Thanks, James. My kids are nearly all growed up now, but since we
haven't watched TV for many years they wouldn't have seen it
anyway.

You can not possibly not know what a Teletubbie is if (a) you lived in
the UK or (b) had kids. More affectation I suspect.
 
K

Kaz Kylheku

That is generally true, but not in this case.

A (type *) cast added to a void * expression increases the restriction,
because unlike the original expression, the augmented expression now no longer
be assigned to an lvalue of arbitrary pointer-to-object type.

But in this case the error that's masked (in poor quality compilers)
is that the expression being cast is not, in fact, a void *
expression, so this is irrelevant.[/QUOTE]

I think that it's boneheaded to worry about poor quality compilers that
do not diagnose calls to undeclared functions.

It's such a compiler which is hiding the error, not the cast. Being
of poor quality, it may be hiding other errors from you, like failing
to generate some other required diagnostics.

You should port your code to better compilers, and follow up on their
diagnostics.
 
I

Ike Naar

The OP should bear in mind that the above statement is one of those
dogmatic, religious statements on comp.lang.c. To be sure, it's a true
statement as it stands, but the devil is in the details.

The only thing you can take away is that "the cast is unnecessary". That's
it. But keep in mind that most whitespace in C code is also unnecessary.
So it's up to you whether you want to use the cast as a matter of style.
In certain idiomatic uses, the cast will let you see at once the type of
pointer on the left side of the assignment.

The error that's being hinted at is a failure to include stdlib.h to get a
proper declaration of calloc(). The masking is a possible problem only in
pre-C99 implementations, since C99 removed implicit function declarations,
and so you'd get your diagnostic anyway. Besides, if you're the kind of
person who forgets to include stdlib.h, then you have bigger issues to
worry about.

What's missing from the statement is the fact that *not* using the cast
can mask certain errors as well. So this whole thing about masking errors
is one big sham, since the argument can be made both ways.

You should also bear in mind that P.J. Plauger, one of the gods in the C
world, has on this very newsgroup defended the use of *alloc() casts for
both style and technical reasons. Of course we had the typical village
idiots like Mark McIntyre screaming foul, but that should at least give
you some perspective about what real-world C programmers think of
comp.lang.c dogma.


Yours,
Han from China
 
K

Keith Thompson

[snip]

Ike, did you mean to add something, or did you just quote HfC's entire
article to get around people's killfiles?

Please don't do that. If I were interested in anything HfC had to
say, I'd read his articles.
 
K

Kenny McCormack

Richard said:
You can not possibly not know what a Teletubbie is if (a) you lived in
the UK or (b) had kids. More affectation I suspect.

I (seriously - not the usual mock ignorance which is so popular on CLC)
don't understand how the Teletubbies came into the discussion. The 'doh'
thing is a Simpsons thing (but I never watched either show myself...)
 
J

Joachim Schmitz

Kenny said:
I (seriously - not the usual mock ignorance which is so popular on
CLC) don't understand how the Teletubbies came into the discussion.

Just look up Ike Naar's first messages in this thread, and you will see.

Bye, Jojo
 
I

Ike Naar

Ike, did you mean to add something, or did you just quote HfC's entire
article to get around people's killfiles?
Please don't do that. If I were interested in anything HfC had to
say, I'd read his articles.

I thought I posted a followup, but apparently something went wrong.
Sorry for that.
 
I

Ike Naar

[To the group: my previous attempt to post a followup failed,
resulting in a full quote of the article I was replying to,
with no added text. My apologies for that.]

[about A = (double *) calloc(MaxValue+1, sizeof(double)); ]
In certain idiomatic uses, the cast will let you see at once the type of
pointer on the left side of the assignment.

No: the cast will only show you the type used in the cast.
The type of the pointer on the left hand side will be compatible
with the type in the cast, but it need not be identical.
See, for instance, the code below; it compiles without any warnings
(using gcc 4.1.2, operating in default mode):

#include <stdlib.h>
int main(void)
{
signed *i = (unsigned*) malloc(0);
void *v = (struct foo*) malloc(0);
double const *d = (double*) malloc(0);
return 0;
}

In all three cases, the type used in the cast is not the exact type
of the pointer on the left hand side.
The error that's being hinted at is a failure to include stdlib.h to get a
proper declaration of calloc(). The masking is a possible problem only in
pre-C99 implementations, since C99 removed implicit function declarations,
and so you'd get your diagnostic anyway. Besides, if you're the kind of
person who forgets to include stdlib.h, then you have bigger issues to
worry about.

Forgetting an #include is a mistake that is easily made.
It is also the kind of mistake that you want to catch at compile time.
 
P

Phil Carmody

You regularly frown upon the use of sms lingo in this forum (and you
have a valid point in doing so).

Just for your information (no offense intended): to a non-native
English speaking person like me, phrases like ``i m'', ``u r'' and
``plz'' are uneasy on the eye, but at least they do make sense.
While ``Duh!'' or ``D'oh!'' mean as much to me as ``aouw meuk!''
would mean to you.

Yup, but you're an ignorant ****, and Keith is speaking lingo
familiar to intelligent English-speaking people since the 80s.
If we are supposed to drop the chatroom speak, then could we drop
the Teletubbie hiccups as well? Please? :)

Only when you evolve from being an ignorant ****.

I can wait 2 decades.

Phil
 
K

Keith Thompson

Phil Carmody said:
Yup, but you're an ignorant ****, and Keith is speaking lingo
familiar to intelligent English-speaking people since the 80s.
[...]

That was extraordinarily rude and completely uncalled for. Are you
having a bad day?
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top