How this function call works???

R

Richard Bos

Programmer Dude said:
Yes you did. My question: why any times? Why participate AT ALL
in making the world an even colder, nastier place than it is?

Non sequitur. If being nasty to an insistent off-topic poster or even
troll makes him go away or even teaches him to keep on topic, that makes
comp.lang.c a more useful and pleasant place, not a colder, nastier one.

Richard
 
G

goose

Programmer Dude said:
Yes you did. My question: why any times? Why participate AT ALL
in making the world an even colder, nastier place than it is?

<singsong>

cos thats how you build an evil empire, silly :)


goose,
evil overload number 9833418898134321993
 
P

Programmer Dude

Richard said:
Non sequitur. If being nasty to an insistent off-topic poster or
even troll makes him go away or even teaches him to keep on topic,
that makes comp.lang.c a more useful and pleasant place, not a
colder, nastier one.

First, clc != the world.

Second, you'll need to demonstrate that such tactics are the ONLY
successful ones.

Third, being nasty is rarely an effective teaching technique.
 
D

Dan Pop

In said:
Third, being nasty is rarely an effective teaching technique.

It is a very effective technique for teaching people to check their
answers before posting them. It certainly worked for me, back when I was
a c.l.c newbie.

Dan
 
B

Blah

Programmer Dude said:
So would breaking their arm. The problem is the side effects.


And no other, less severe, technique would?

For some people, possibly not. Using myself as an example, I once
posted a mostly but not completely accurate reply to a debugging request.
The information I got wrong was certainly available in a fair number of C
references that I could have used to check. But I didn't. I got two polite
corrections and one flaming correction (from Dan Pop no less). At the time
I was quite irritated, but a few things resulted from that.

1) I got over it.
2) I made more of an effort to check myself for correctness.
3) I still remember the details of what I inaccurately posted, and I am not
likely to make the mistake again.

So, while I was anything but happy about the not-so-polite response when I
received it, I learned to be more careful about what I post, and I learned
something that stuck with me.

Chances are fairly good that I would not have learned either of those things
had everyone been nice about it. Of course, not all people are the same,
and flaming may be counterproductive in some cases, but there are times when
it is both necessary and useful.
 
R

Richard Bos

Programmer Dude said:
First, clc != the world.

Exactly. So just because we apply a bit of well-warranted heat to a
repeating airhead here on c.l.c, that doesn't mean we're out to kick
your puppy or something.
Second, you'll need to demonstrate that such tactics are the ONLY
successful ones.

Third, being nasty is rarely an effective teaching technique.

We're not talking about first-time posters, here. First-time offenders
do always deserve a civilised reply, provided they don't start off
abusive - and if they do, they're probably just trolls anyway. Nasty
replies are only warranted if someone has repeatedly been asked to post
nicely, and doesn't seem to want to get the point, or if they have been
asked politely to be topical and then turn nasty themselves. In those
cases, the civilised reply has been proven not to work; and at a guess,
in 90% of those cases a little heat does prove to either scare them off
or reform them.

Richard
 
D

Dan Pop

In said:
So would breaking their arm. The problem is the side effects.

Precisely. A bruised ego is the worst side effect of a nasty correction
when a nasty correction is due.

There are a few posters who really deserve a broken arm for their
perseverance in posting wrong answers.
And no other, less severe, technique would?

There are cases (the above mentioned posters) where neither polite nor
nasty corrections help (and breaking their arm is, unfortunately, not an
option :) But, for most people, the nasty correction is more
effective than the polite one. It motivates them to avoid posting
unchecked answers in the future (no such motivation from a polite
correction). The newsgroup greatly benefits from that. It's a dirty
job, but someone has to do it. I'm greatly indebted to the people
who flamed me when I deserved to be flamed.

Dan
 
J

John Bode

Java Böy said:
could some body help me what's happening here...

In general, it's shoehorning a hand-coded x86 assembly subroutine into
a C program.

As Dan and others have pointed out, this code is not legal in ISO C.
However, depending on the compiler, you can get an executable that
does what you intend, but that's a happy accident more than anything
else.
thanks..

char sc[] =
"\x31\xc0" /* xor %eax, %eax */
"\x50" /* push %eax */
"\x68\x2f\x2f\x73\x68" /* push $0x68732f2f */
"\x68\x2f\x62\x69\x6e" /* push $0x6e69622f */
"\x89\xe3" /* mov %esp,%ebx */
"\x50" /* push %eax */
"\x53" /* push %ebx */
"\x89\xe1" /* mov %esp,%ecx */
"\x31\xd2" /* xor %edx,%edx */
"\xb0\x0b" /* mov $0xb,%al */
"\xcd\x80"; /* int $0x80 */

sc is being used to store the actual machine code for the operations
described in the comments (opcodes and data). Each "\x.." entry
represents a single byte. Each line of bytes consists correpsonds to
operation listed in the comment.

If you look at this array in a debugger you will see something like

sc+0: 31 c0 50 68 2f 2f 73 68
sc+7: 68 2f 62 69 6e 89 e3 50
....
main()
{
void (*fp) (void); // what is happening at this line

This declares fp as a pointer to a function returning void with no
parameters.
fp = (void *)sc;

This assigns the address of sc to fp, allowing the bytes of the array
to be executed as a function by main(). Unfortunately, it's a bad
assignment for several reasons. First of all, the cast expression
isn't even correct; the type of fp isn't void *, it's void (*)(void).
Secondly, this type of conversion (from pointer to object to pointer
to function) isn't allowed under ISO C. It may have been allowed in
earlier implementations, and some compilers may still allow it if you
don't have strict conformance turned on.

And this calls the function.

[snip]
 
P

Programmer Dude

Richard said:
Nasty replies are only warranted if someone has repeatedly been
asked to post nicely, and doesn't seem to want to get the point,
or if they have been asked politely to be topical and then turn
nasty themselves. In those cases, the civilised reply has been
proven not to work; and at a guess, in 90% of those cases a
little heat does prove to either scare them off or reform them.

One can't help but wonder if quietly ignoring them might not be
more effective and with less potential for flamewars.

But whatever. Your group, your rules. (-:
 
D

Default User

Dan said:
Precisely. A bruised ego is the worst side effect of a nasty correction
when a nasty correction is due.

I disagree with this very strongly. I think are much better off
correcting the person firmly and succinctly. If the person doesn't wish
to listen or argues in a foolish manner, then perhaps. But to always
have the opening shot be abusive is ludricrous. It's more likely to
bring out a defensive response and make the subject less likely to
listen to what you have to say.

I respect your knowledge, but increasingly of late I do not respect you.
I compare your style with the thorough and gentlemanly manner of Chris
Torek, and you come up very short.




Brian Rodenborn
 
R

Richard Bos

Programmer Dude said:
One can't help but wonder if quietly ignoring them might not be
more effective and with less potential for flamewars.

I've seen groups where this happened. The answer is a resounding "no".
But whatever. Your group, your rules. (-:

No, _our_ group. All non-moderated groups are the group of the regulars,
_all_ the regulars.

Richard
 

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
474,077
Messages
2,570,566
Members
47,202
Latest member
misc.

Latest Threads

Top