Re: pointer q




"Flash Gordon" <spam@xxxxxxxxxxxxxxxxxx>
Joe Smith wrote:
"RSoIsCaIrLiIoA" <zz@xxxx> wrote in message
news:9odg62tc13dv6m60mlsq19h4caf5ff06ij@xxxxxxxxxx

[snip]
#include <stdio.h>

int main ( void )
{long l = 420000;
long *lp = &l;

short *sp;
*sp = (short)*lp; /* ill-advised, but Let's Pretend */

This is very different. If you were trying to fix the code further up so
it would compile what you wanted was:
short *sp = (short*)*lp; /* ill-advised, but Let's Pretend */
How thick is my head ^ ?

[snip]
Try it on both big and little endian systems, you can even do it with a
pencil and paper if you don't have both, you will then see the very
different results.

As a general rule casting is a bad idea. There are a few places where it
is required,

As to the syntax on the printf, I've done
everything short of Dedekind cuts on table B-1 and am still pulling out
my hair.

printf is relatively simple, it is scanf that is tricky! If you want to
ask specific questions about printf where you can't understand your text
book I'm sure someone will answer them.
I sometimes mistake the one table for the other!


I'm afraid that I don't know what Bugtraq is ... probably at my own
peril.

Basically a database of bugs.
Sounds like something that, according to fashion, merits a huge investment.

Am I correct to think that a type of masking occurs here? joe

No, not masking. More a case of only reading part of the data with my
"fix". Or with your code writing to an uninitialised pointer and causing
half of your socks to migrate to Alaska.
Am I not reading, with correction, the number that a smaller type thinks a
larger type was? My socks are well accounted for, but Scott Knuds not only
flew out of my hard drive, but is eating my lunch.

BTW, I would not place too much face in anything posted by RSoIsCaIrLiIoA.
A Google search and seeing how often it has posted assembler will show you
why many people probably have it kill filed.
He sounds like a dude, so you can be assured that I won't give him face, but
until otherwise motivated, I'll give him the benefit of the doubt. Thanks
for your reply. Joe



.



Relevant Pages

  • Re: printf on a very small floating point number
    ... i.e. what flag would ... use scientific notation(see options of printf). ... code in the debugger, the values are indeed zero, not just a very ... I have done it with microseconds, by reading a cpu ...
    (comp.lang.c)
  • Re: eof problems in read double data from a file
    ... short initRead { ... fprintf (stderr, "End of reading file\n"); ... printf; ... With "rb" you avoid any translation. ...
    (comp.lang.c)
  • Re: printf on a very small floating point number
    ... use scientific notation(see options of printf). ... code in the debugger, the values are indeed zero, not just a very ... It looks like I don't have a good way to time function ... I have done it with microseconds, by reading a cpu ...
    (comp.lang.c)
  • Re: NBC Sweeny Todd
    ... I'm reading Ruth's post as something along the lines of "It knocked my socks ... No spoilers ... Debbie ...
    (rec.music.artists.springsteen)
  • Re: sending echo to all clients
    ... reading all the bytes at once. ... then with printf() and flush, ... which is received and sent to clients. ... This line is *server* debug output. ...
    (comp.unix.programmer)