Memory corruption on freeing a pointer to pointer

K

Keith Thompson

David Brown said:
Much of C assumes the ordering from English. Non-native speakers don't
have to like it, but they do have live with it - just as people who
write /proper/ English have to accept that the developers of the C
language can't spell "maths" properly.

Or "behaviour".

But "behavior" doesn't appear as a standard header name. Maybe you can
think of "math" as an abbreviation of "maths", just as "stddef" is an
abbreviation of "standard definitions". :cool:}
 
K

Keith Thompson

James Kuyper said:
On 08/27/2013 04:24 AM, Ike Naar wrote: [...]
Examples:

int var;
int const con;
char *s1, *s2;

(42 == var); /* Yoda condition */
(con == var); /* Yoda condition */
(42 == var+1); /* not Yoda condition */
(42 == con); /* not Yoda condition */
(0 == strcmp(s1, s2)); /* not Yoda condition */

Right?

All of the above correctly describes the concept that I'm thinking of.
The use of the phrase "modifiable lvalue" marks this as specific to C,
C++ and related languages. More generally, a Yoda condition is the use
X==Y rather than Y==X, despite the equivalence of those expressions, to
protect against the typo == > =, because X=Y would be invalid, but Y=X
would not be. The details of what makes X=Y invalid could vary from one
language to another, and of course the concept is meaningless for
languages which don't have both = and ==.

If the people who actually use the term "Yoda condition" want to use it
in a more restricted sense, such as the one you mentioned from
Wikipedia, I'm certainly in no position to stop them; but I would
recommend adopting this definition.

I still think of (0 == strcmp(s1, s2)) as a Yoda condition; that
particular case doesn't guard against "==" vs. "=" errors, but the
cultivated habit of putting the constant on the left does.

http://hegeekshegeek.files.wordpress.com/2012/06/yoda-beatles.jpg
 
K

Keith Thompson

Phil Carmody said:
Keith Thompson said:
James Kuyper said:
On 08/24/2013 03:05 PM, Sharwan Joram wrote: [...]
if ( NULL == parameters[parametercount]){

This is what's known as a "Yoda conndition"
<http://en.wikipedia.org/wiki/Yoda_Conditions>. I know that a lot of
programmers like them, and for somewhat valid reasons, but personally I
find them jarring and unnecessary.

They are a shibolleth for me. If I see them, I am 99% sure the code
was written by a fuckwit or a newb, and I should be very very careful
about everything else from the same source.
[snip]

Let's just say that Yoda conditions upset me less than they seem to
upset you.
 
J

James Kuyper

(snip)


I once knew that in Europe, English classes were taught in England
English and not US English. I suppose I would expect that from other
(than US) former English colonies, too.

Seems to me that US is louder, but maybe there aren't more of us.

-- glen
<http://en.wikipedia.or/wiki/English_language#Geographical_distribution>

There's an awful lot of dark blue in that pie chart. The UK wouldn't
have a majority of the native speakers of English even if the US,
Canada, and Australia all suddenly disappeared.
 
J

Joe Pfeiffer

James Kuyper said:
<http://en.wikipedia.or/wiki/English_language#Geographical_distribution>

There's an awful lot of dark blue in that pie chart. The UK wouldn't
have a majority of the native speakers of English even if the US,
Canada, and Australia all suddenly disappeared.

When my daughter spent a semester as an exchange student in Germany, the
teacher not only taught UK English, he also tried to correct her
American pronunciations and slang.
 
I

Ian Collins

David said:
Maybe my humour was too subtle for you - perhaps I should have included
a smiley. While it is common amongst the British to joke about
American's not speaking or writing proper English, it is only a joke -
no one takes it seriously.

Except Americans.
 
M

Malcolm McLean

When my daughter spent a semester as an exchange student in Germany, the
teacher not only taught UK English, he also tried to correct her
American pronunciations and slang.
In the the Chalet School stories, set in an Anglophone school in the Swiss
Alps, the girls are reprimanded for "smashing".
 
J

James Kuyper

Maybe my humour was too subtle for you - perhaps I should have included
a smiley. While it is common amongst the British to joke about
American's not speaking or writing proper English, it is only a joke -
no one takes it seriously.

Sorry - I was in a bit of a bad mood, for reasons that had nothing to do
with your message or this newsgroup.

If you'd added a smiley to your message, I might have added one to mine
- but I don't think I would have changed anything else except dropping
the "Get over it". That was definitely influenced by my bad mood.

....
Most English speakers around the world are not American /or/ British.

If you restrict it to native speakers, most (58%) are American.
 
G

glen herrmannsfeldt

(snip, someone wrote)
(snip, then I wrote)
(snip)

There's an awful lot of dark blue in that pie chart. The UK wouldn't
have a majority of the native speakers of English even if the US,
Canada, and Australia all suddenly disappeared.

Oh, yes, I was thinking about non-native speakers, too.

As much of science is done in English, many students will learn
English to do science.

According to the table, but not in the pie chart, there are many
second and third language English speakers in India, Pakistan,
and Nigeria. The second language English speakers from Europe
aren't in that chart. I will guess that India and Pakistan use
England English, and that Philippines uses American English.

-- glen
 
G

glen herrmannsfeldt

(snip of England and American English)
Or "behaviour".
But "behavior" doesn't appear as a standard header name. Maybe you can
think of "math" as an abbreviation of "maths", just as "stddef" is an
abbreviation of "standard definitions". :cool:}

Seems to me that math should be an abbreviation, but that it is
not normally written with a period like most abbreviations.

OK, so why stddef and not stddefs?

If I pick peas, then I can make pea soup. (But not peas soup.)

-- glen
 
K

Keith Thompson

glen herrmannsfeldt said:
Seems to me that math should be an abbreviation, but that it is
not normally written with a period like most abbreviations.

OK, so why stddef and not stddefs?

Because, IIRC (I.I.R.C.?), some ancient file systems permitted only six
characters for the file name plus one for the extension.
 
B

Ben Bacarisse

Ike Naar said:
James Kuyper said:
On 08/24/2013 03:05 PM, Sharwan Joram wrote: [...]
if ( NULL == parameters[parametercount]){

This is what's known as a "Yoda conndition"
<http://en.wikipedia.org/wiki/Yoda_Conditions>. I know that a lot of
programmers like them, and for somewhat valid reasons, but personally I
find them jarring and unnecessary. Personally, I'd write that as:

if (parameters[parametercount] == NULL) {

Does it matter? The == operator is symmetric, (X==Y) == (Y==X).

If (X==Y) is jarring and unnecessary, then, for symmetry reasons
(Y==X) is unnecessary and jarring.

That sounds like a quasi-mathematical argument, but mathematicians don't
do this. I can't recall ever seeing "let 0 = x" or "for all 2 < x" in a
maths paper[*] (it may have happened but the rarity is the thing). The
only place where it occurs with any frequency in the rather natural
notation for a range: "0 < x < 1". Mathematicians know that it is hard
enough to read the damn stuff, without the author throwing up
road-blocks in the way. We, as programmers, are in the same boat.

The people who know about this stuff (what's easy and what's hard to
read) are not computer scientists and logicians, but linguists and
psychologists. What little I know of both, strongly suggests that
natural language is easy for us, but maths and programming are not.
Narrowing that gap is likely to be helpful, and English, for one, is not
symmetrical with its verbs: there is a subject and an object even when
that is not logical. We are not Vulcan.

[*] You might see that in a text about formal logic where 0 is being
defined, but that's just another confirmation of my point.

<snip>
 
B

Ben Bacarisse

David Brown said:
Maybe my humour was too subtle for you - perhaps I should have included
a smiley. While it is common amongst the British to joke about
American's not speaking or writing proper English, it is only a joke -
no one takes it seriously.

It's a risky joke. The UK is not free of bigots and xenophobes. I know
at least one person who'd say that in all seriousness, and take it
seriously if someone else said it. I'm not sure that even using a
smiley will work in such situations, Twitter has spoilt it
#innocentface.

<snip>
 
G

glen herrmannsfeldt

(snip, I wrote)
Because, IIRC (I.I.R.C.?), some ancient file systems permitted only six
characters for the file name plus one for the extension.

I know some with six and three for extension.

-- glen
 
M

Malcolm McLean

I certainly can't argue about how the British "lost control" of the
English language - when you get lots of other people to speak the
language, your influence falls proportionally. But I have never seen
any indication that "the English", or "the British", have ever /wanted/
to keep control over the language.
Some countries have a language academy. For instance there's one in French
which bans English terms like "le hotdog" and demands "chien chaude" or
whatever it is they think French people should say. Hebrew has one too,
it's recently ruled that the feminine plural may be used when addressing
a mixed group mainly of women.
But we've never had one in English. The closest thing is the politically
correct lobby which insists on "chairperson", bans slang terms for a Negro,
and so on. But they still don't have any official standing.
 
J

James Kuyper

On 08/28/2013 03:39 AM, David Brown wrote:
....
I certainly can't argue about how the British "lost control" of the
English language - when you get lots of other people to speak the
language, your influence falls proportionally. But I have never seen
any indication that "the English", or "the British", have ever /wanted/
to keep control over the language.

Any serious complaint about the differences between British English and
any of the other dialects that is worded to suggest that the British
ones are superior implies such a desire. Your complaint was apparently
not serious, but it had that form. I've known people to make such
complains seriously, which is why I responded poorly to it.
... And different dialects and
variations of the language have developed around the world (and also
within the UK - if you visited the Scottish Borders, you probably
wouldn't understand a word people said - other Scots have trouble enough).

I spent a year studying advanced maths at Cambridge (at least, that's
what they called it - in the US, we call things like General Relativity
Quantum Field Theory, and String Theory advanced Physics, though
there's certainly also a lot of advanced mathematics involved).
During that time I met people from all over the British Commonwealth,
speaking a variety of dialects (now that I think about it, I don't
recall meeting any Scots, which seems odd). No one was impolite enough
to express anti-US sentiments while I was around (as one of them pointed
out to me :) ). However, I was surprised to hear several of them
express strong prejudices based upon the differences between English
dialects from places separated by no more than few hundred kilometers,
such as York and London.
It seemed to me that, while all of the British dialects shared common
differences in grammar and vocabulary from US English, that the
difference in pronunciation between US English and the Queen's English
was much smaller than the differences between the various British dialects.
 
I

Ike Naar

Ike Naar said:
On 08/24/2013 03:05 PM, Sharwan Joram wrote:
[...]
if ( NULL == parameters[parametercount]){

This is what's known as a "Yoda conndition"
<http://en.wikipedia.org/wiki/Yoda_Conditions>. I know that a lot of
programmers like them, and for somewhat valid reasons, but personally I
find them jarring and unnecessary. Personally, I'd write that as:

if (parameters[parametercount] == NULL) {

Does it matter? The == operator is symmetric, (X==Y) == (Y==X).

If (X==Y) is jarring and unnecessary, then, for symmetry reasons
(Y==X) is unnecessary and jarring.

In simple term - bollocks.

Was 10 seconds less than the time you spent thinking before posting
your reply?

How long did you spend thinking about yours?
 
I

Ike Naar

It depends entirely on context. Base plus offset would be my general
preference. So:

buffer_end = buffer_start + 0x4000;

but:

regs = 0x40008c00 + bank_offset;

So, for the '+' operator it may depend on context,
but for the '==' operator it should depend on dogma?
 

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
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top