"Mastering C Pointers"....

R

Richard Heathfield

Alan said:
Now shut the **** up and get the hell out of my life
you stupid punk.

What an erudite vocabulary you have. Have you ever considered civility as an
alternative to scatology? It is a much more pleasant way to communicate.
killfiled for 90 days. The other post goes unread.

He will be devastated to learn that. Simply devastated.
 
M

Mark McIntyre

You make a better case than I thought existed.
ha!

Lacking the time right now to make a detailed study of the matter,

certainly, Pierre. :)
Would you suggest that, say, 0 is an object?

<ot>
At the risk of sinking my own battleship, not if its a literal. IME
its converted cheaply into either a handy zero byte or nothing at all
in machine code, thus being a non-addressable item.
CMP A1,0
JNE 0xDEAD:BEEF
EVAL A1
JZ 0xFFFF:F000
</ot>
 
C

Christian Bau

James Hu said:
Can someone remind me what the on-topic lesson was? Here's my stab:

* For unsigned integral types, shift vs. multiply/divide by powers
of 2 are equivalent in C.
* For signed integral types, shift vs. multiply/divide by powers
of 2 in C depends on the implementation. If you want strictly
conforming code, you must use divide.

Did I get that right?

Not quite. For signed integral types, the result of a right shift for
negative numbers is implementation defined, and right shift by (n) is
usually not the same as division by 2^n. If you want a division, you
must divide. If you want a right shift, you must right shift. You
usually don't want a right shift.

Some people try to "optomize" by replacing division by a power of two
with a right shift. (I used the word "optomize" because it is usually
not a worthwhile optimization and a surprisingly high number of people
using this technique can't spell "optimize" correctly). The result: For
negative numbers, it is usually incorrect. For positive numbers, the
savings are tiny. For unsigned values, there is no saving.

You should also note that for negative numbers, you really have to
figure out what result you really want. C integer division rounds
towards zero (in C99. I think in C90 it was implementation defined for
negative values). However, quite often you want to round down, even for
negative values, and then a C division doesn't give the result you want.
 
M

Mark McIntyre

Roose must be one of those who believe it is right to teach people to
do things the wrong way first, and then later tell them out of the
blue: "Everything I previously taught you is wrong! Forget all about
it! Do things this way instead!". I can never understand how such
teaching could possibly be more favourable than teaching how to do
things right from the start.

Well, TBH, having taught both 1st year undergrads and school kids, I
can see the virtues of this approach. It makes little sense to try to
teach eleven year olds quantum mechanics and wave theory, unless they
first have some inkling of the periodic table and chemical reactions.
It works better to teach people in much the same way that we
historically discovered it - chemicals, molecules, atoms, subatomic
particles, wave theory, quarks, strings... or whatever.

Thats not to say that teaching programming beginners utter tripe is my
recommendation. By all means start by teaching them how to read
punched cards tho, then progress on to hand-crafted assembler on an
11/780 or a 68000 :)
 
M

Mark McIntyre

No, not everyone. I have no problem with it whatsoever.

An twere not you, this would have engendered a flame response. As it
is, my toasting fork is at the ready.
is really screwed up, I can easily Go Ogle the orginals (assuming
they aren't available on the local server).

What, you are happy to waste *your* time finding out stuff others were
discurteous enough to snip out? Gah. Thats like paying terrorists
off... :)
Top posting offers the *advantage* of giving me a peek at what the
poster has to say immediately. All the easier for me to determine
if the post is worth reading.

Indeedy. Darwinian I call it. Come to think on it, maybe we should
*encourage* it amongst certain posters here...
 
M

Mark McIntyre

Data are the raw materials of information.

Indeed. But I consider data to be both what goes into a computer
(example: some graphs I digitised for my DPhil thesis) and comes out
(example: some tables of stress/strain analysis that I generated from
the digitised graphs). Both form information.

Data need, indeed, not even reach a computer in the first place. The
cricket scores in the college ground next to my house are undoubtedly
data, but I strongly suspect that they never go nearer a computer
than they are to my study, given the antiquity of both the scorer and
the pavilion scoreboard. I'm generally surprised that such a decrepit
old guy can lift those heavy metal plates to hang them on the hooks,
and that, having got them there, he's not brained by them when they
fall off again, the hooks being so rusty... :)
 
P

Peter Shaggy Haywood

Groovy hepcat Mark McIntyre was jivin' on Mon, 03 Nov 2003 23:46:35
+0000 in comp.lang.c.
Re: "Mastering C Pointers"....'s a cool scene! Dig it!
I'm sorry, did you just killfile RJH?

He wouldn't be the first. Lots of trolls plonk the clueful regulars
here. It's what trolls do when they find they can't argue with reason.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
 
N

nobody

Christian Bau said:
[useful stuff snipped]

Some people try to "optomize" by replacing division by a power of two
with a right shift. (I used the word "optomize" because it is usually
not a worthwhile optimization and a surprisingly high number of people
using this technique can't spell "optimize" correctly).

<ot>
Oh. And my 1st impession was you've used it because it rhymes
with "lobotomize" ;-)
</ot>
[snip]

Thanks to everyone for information.
 
M

Mark McIntyre

Yeah, that was kind of my point. :)

And I revert to my point - as the Standard says, a null pointer
constant must be converted to a pointer type before it can be compared
to a pointer. I still reckon that conversion requires storage.
 
J

Jim Showalter

I'm happy for you. Now shut the **** up and get the hell out of my life
you stupid punk.

That's the whong answer.

Think about it: if Alan Connor is a real person, unconnected to Roose,
his reply would be one of incrediblity at such an assertion. Instead, he
reacts with genuine anger - like a thief caught in the act.
killfiled for 90 days. The other post goes unread.

Oh dear - I'll be counting the days.

Wonder what he meant by "The other post goes unread."?


jim
--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/
_/ I'm all for computer dating, but I wouldn't want my sister to marry
_/ one.
_/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
 
S

Sheldon Simms

And I revert to my point - as the Standard says, a null pointer
constant must be converted to a pointer type before it can be compared
to a pointer. I still reckon that conversion requires storage.

I agree that the conversion must take place, but I don't agree
that it requires storage. A null pointer constant exists in source
code, but neither the null pointer constant nor the null pointer
need to exist at all in an executable program/object file/library,
etc. The conversion takes place in the compiler and may end up
being a conceptual conversion rather than an actual conversion.

For example, the code:

char * p;
...
if (p != 0) /* <-- here's a null pointer constant */
{
do_stuff();
}
do_other_stuff();

might be translated:

tst r9 ;evaluate p and set flags
beq .L54
bsr do_stuff
..L54:
bsr do_other_stuff

No null pointer, object or value, at all.
 
R

Richard Heathfield

Mark said:
And I revert to my point - as the Standard says, a null pointer
constant must be converted to a pointer type before it can be compared
to a pointer. I still reckon that conversion requires storage.

Well, that's already been answered elsethread.

Your original point, with which I originally disagreed, was "(&a) in that
context is an expression. To be a pointer, it would have to be stored in
something. ."

Now, you already agree that &a is an expression that is not stored in
something. Great. You're right. Now let's see if we can work out, purely
from reference to the Standard, whether &a is also a pointer.

6.5.3.2 says:

"The unary & operator returns the address of its operand. If the operand has
type "type", the result has type "pointer to type".

QED.
 
J

Joona I Palaste

but u are about the only one, I reckon

No wonder it got us stumped. I never thought you Mark would write in
h4x0r d00dsp33k.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The day Microsoft makes something that doesn't suck is probably the day they
start making vacuum cleaners."
- Ernst Jan Plugge
 
M

Mark McIntyre

"The unary & operator returns the address of its operand. If the operand has
type "type", the result has type "pointer to type".

You got me. However I now use a cunning manoeuvre, and note that the
original expression had no side-effects and would have been removed by
the compiler during optimisation. So it still wasn't a pointer !! :)
 
J

Joona I Palaste

Fat fingers - should have been a Y....

OK, I see.
Hmm, how about a VCR tape containing sample episodes of that quiz show
you and Richard are so fond of? It sounds so eccentrically British, I
want to see what it looks like.
 
M

Mark McIntyre

Hmm, how about a VCR tape containing sample episodes of that quiz show
you and Richard are so fond of?

Err... Its a radio show.
It sounds so eccentrically British, I
want to see what it looks like.

it would certainly be eccentric to watch it. white noise video
perhaps? :)
 

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

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top