473,396 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How this function call works???


could some body help me what's happening here...

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 */

main()
{
void (*fp) (void); // what is happening at this line

fp = (void *)sc;
fp();
}

--
A day spent without Linux is a day spent without learning!
-- Java Böy


---
Posted via news://freenews.netfront.net
Complaints to ne**@netfront.net
Nov 13 '05 #1
25 3194
"Java Böy" <ja*****@zapo.net> wrote:

could some body help me what's happening here...

char sc[] =
"\x31\xc0" /* xor %eax, %eax */ [...] "\xcd\x80"; /* int $0x80 */

main()
{
void (*fp) (void); // what is happening at this line
This line declares the variable fp as an pointer to an function of void
which returns void.

fp = (void *)sc;
fp();
}


Let me give you an example (hopefully) easier to understand:

#include <stdio.h>

void foo(void)
{
printf("Hallo Welt\n");
}

int main(void)
{
void (*f)(void); // declare a pointer to a function

f = foo; // assign the address of foo to the pointer f
f(); // call the function f points to -> foo

return 0;
}

The additional problem with the program given by you is that the
function is not declared as one, but as a array of chars char sc[] =...
This array is initialized with some 80x86 assembler hexcodes which end
int some linux kernel call I don't know... Hopefully it will terminate
the program for there is no return instruction in the function.

BTW: main doesn't need to be a function either :)

long long main = 0xC300000000B8; // int main(void) { return 0; }
Nov 13 '05 #2
On Fri, 1 Aug 2003 01:27:26 +0500, "Java Böy" <ja*****@zapo.net> wrote
in comp.lang.c:

could some body help me what's happening here...

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 */

main()
The current C standard requires that main() be defined with a return
type of int.
{
void (*fp) (void); // what is happening at this line
Defines fp to be a pointer to a function that takes no arguments and
returns nothing.
fp = (void *)sc;
This is undefined behavior. There is no cast from pointer to char to
pointer to function of any kind defined in C. At this point you do
not have a C program anymore.
fp();
}


Whatever happens when you attempt to call an array of characters via a
pointer to a function has nothing to do with C. On many platforms it
will just plain crash. If you want to find out what someone expected
it to do on one particular compiler, you might try asking in a group
that discusses that particular compiler.

As far as the C language is concerned, anything that happens during or
after the assignment of the array to the function pointer is just as
correct or incorrect as anything else.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #3
On Thu, 31 Jul 2003 22:42:57 +0200, Jens Schicke <dr******@gmx.de>
wrote in comp.lang.c:
"Java Böy" <ja*****@zapo.net> wrote:

could some body help me what's happening here...

char sc[] =
"\x31\xc0" /* xor %eax, %eax */ [...]
"\xcd\x80"; /* int $0x80 */

main()
{
void (*fp) (void); // what is happening at this line


This line declares the variable fp as an pointer to an function of void
which returns void.

fp = (void *)sc;
fp();
}


Let me give you an example (hopefully) easier to understand:

#include <stdio.h>

void foo(void)
{
printf("Hallo Welt\n");
}

int main(void)
{
void (*f)(void); // declare a pointer to a function

f = foo; // assign the address of foo to the pointer f
f(); // call the function f points to -> foo

return 0;
}

The additional problem with the program given by you is that the
function is not declared as one, but as a array of chars char sc[] =...
This array is initialized with some 80x86 assembler hexcodes which end
int some linux kernel call I don't know... Hopefully it will terminate
the program for there is no return instruction in the function.

BTW: main doesn't need to be a function either :)


We discuss the C language here. If you want to spout bullsh*t, go
somewhere else.
long long main = 0xC300000000B8; // int main(void) { return 0; }


If you think the above is C, you are brain-damaged.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Nov 13 '05 #4
In <bg*********@imsp212.netvigator.com> "Jeff" <no****@notexist.com> writes:

"Java Böy" <ja*****@zapo.net> wrote in message news:bg**********@adenine.netfront.net...

could some body help me what's happening here...

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 */

main()
{
void (*fp) (void); // what is happening at this line

fp = (void *)sc;
fp();
}
Just for your information, I think your code (including the assembly part) *is not illegal* in C,
in fact

From ISO/IEC 9899:1999
-------------------------------------
J.5.7 Function pointer casts


Do you have the slightest clue about the connection between J.5 and the
normative part of the C99 standard?
1 A pointer to an object or to void may be cast to a pointer to a function, allowing data to
be invoked as a function (6.5.4).
Where can you see such a cast in the OP's code? Are you visually impaired
or merely a patent idiot?
From line 1 "allowing data to be invoked as a function"


What about it?

And what about the following quote from the *normative* part of the same
standard:

6.5.16.1 Simple assignment

Constraints

1 One of the following shall hold:93)

- the left operand has qualified or unqualified arithmetic type
and the right has arithmetic type;

- the left operand has a qualified or unqualified version of a
structure or union type compatible with the type of the right;

- both operands are pointers to qualified or unqualified versions
of compatible types, and the type pointed to by the left has
all the qualifiers of the type pointed to by the right;

- one operand is a pointer to an object or incomplete type and
the other is a pointer to a qualified or unqualified version
of void, and the type pointed to by the left has all the
qualifiers of the type pointed to by the right;

- the left operand is a pointer and the right is a null pointer
constant; or

- the left operand has type _Bool and the right is a pointer.

Which of these alternatives is matched by fp = (void *)sc; ?
Any idea about what happens when a constraint is violated?

If the line in question was:

fp = (void(*)(void))sc; /* no 6.5.16.1 constraint violation */

the code would have invoked undefined behaviour and the quote from J.5.7
would have explained why such code *may* work on *certain*
implementations (still without giving it *any* legitimation).

It doesn't hurt to get a clue before posting irrelevant quotes from the
standard!

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #5

"Dan Pop" <Da*****@cern.ch> wrote in message news:bg**********@sunnews.cern.ch...
In <bg*********@imsp212.netvigator.com> "Jeff" <no****@notexist.com> writes:

"Java Böy" <ja*****@zapo.net> wrote in message news:bg**********@adenine.netfront.net...

could some body help me what's happening here...

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 */

main()
{
void (*fp) (void); // what is happening at this line

fp = (void *)sc;
fp();
}

Just for your information, I think your code (including the assembly part) *is not illegal* in C,in fact

From ISO/IEC 9899:1999
-------------------------------------
J.5.7 Function pointer casts


Do you have the slightest clue about the connection between J.5 and the
normative part of the C99 standard?
1 A pointer to an object or to void may be cast to a pointer to a function, allowing data to
be invoked as a function (6.5.4).


Where can you see such a cast in the OP's code? Are you visually impaired
or merely a patent idiot?
From line 1 "allowing data to be invoked as a function"


What about it?

And what about the following quote from the *normative* part of the same
standard:

6.5.16.1 Simple assignment

Constraints

1 One of the following shall hold:93)

- the left operand has qualified or unqualified arithmetic type
and the right has arithmetic type;

- the left operand has a qualified or unqualified version of a
structure or union type compatible with the type of the right;

- both operands are pointers to qualified or unqualified versions
of compatible types, and the type pointed to by the left has
all the qualifiers of the type pointed to by the right;

- one operand is a pointer to an object or incomplete type and
the other is a pointer to a qualified or unqualified version
of void, and the type pointed to by the left has all the
qualifiers of the type pointed to by the right;

- the left operand is a pointer and the right is a null pointer
constant; or

- the left operand has type _Bool and the right is a pointer.

Which of these alternatives is matched by fp = (void *)sc; ?
Any idea about what happens when a constraint is violated?

If the line in question was:

fp = (void(*)(void))sc; /* no 6.5.16.1 constraint violation */

the code would have invoked undefined behaviour and the quote from J.5.7
would have explained why such code *may* work on *certain*
implementations (still without giving it *any* legitimation).

It doesn't hurt to get a clue before posting irrelevant quotes from the
standard!

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de


I understand what is the problem. Thank you for your explanation.

--
Jeff
Nov 13 '05 #6
# In <bg**********@adenine.netfront.net> "Java Böy" <ja*****@zapo.net> writes:
#
#
# could some body help me what's happening here...
#
# 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 */
#
# main()
# {
# void (*fp) (void); // what is happening at this line
#
# fp = (void *)sc;
# fp();
# }

It's a hand-coded system or bios interrupt call. You can probably
get more information about the call from an intel newsgroup.
Rather than use some kind 'asm' insert or separate assembly file,
someone figured out all the opcodes and inserted them into the
char array. The data pointer to this is forced into a code pointer
and then the code is executed with a function call mechanism.

The code is, of course, machine specific. And to some degree so
is converting a data pointer to a code pointer: on some machines
they are very different creatures.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
What kind of convenience store do you run here?
Nov 13 '05 #7
In article <vi************@corp.supernews.com>,
Derk Gwen <de******@HotPOP.com> wrote:
It's a hand-coded system or bios interrupt call. You can probably
get more information about the call from an intel newsgroup. ...
The code is, of course, machine specific. And to some degree so
is converting a data pointer to a code pointer: on some machines
they are very different creatures.


Oddly enough, one of those machines is the very machine for which
it is written: the Intel IA32.

If the CPU's registers were set up so as to deter certain forms of
viruses, the code would not work at all. Fortunately for the
original author, however, most people prefer to get the wrong
answer as fast as possible. :-)
--
In-Real-Life: Chris Torek, Wind River Systems (BSD engineering)
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 13 '05 #8
Why is everyone in these newsgroups so friggin nasty and mean? This is why
usenet has gone to crap and it is now virtually useless as a mechanism for a
newby to get any kind of help.
"Dan Pop" <Da*****@cern.ch> wrote in message
news:bg**********@sunnews.cern.ch...
In <bg*********@imsp212.netvigator.com> "Jeff" <no****@notexist.com> writes:
"Java Böy" <ja*****@zapo.net> wrote in message news:bg**********@adenine.netfront.net...

could some body help me what's happening here...

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 */

main()
{
void (*fp) (void); // what is happening at this line

fp = (void *)sc;
fp();
}

Just for your information, I think your code (including the assembly part) *is not illegal* in C,in fact

From ISO/IEC 9899:1999
-------------------------------------
J.5.7 Function pointer casts


Do you have the slightest clue about the connection between J.5 and the
normative part of the C99 standard?
1 A pointer to an object or to void may be cast to a pointer to a function, allowing data tobe invoked as a function (6.5.4).


Where can you see such a cast in the OP's code? Are you visually impaired
or merely a patent idiot?
From line 1 "allowing data to be invoked as a function"


What about it?

And what about the following quote from the *normative* part of the same
standard:

6.5.16.1 Simple assignment

Constraints

1 One of the following shall hold:93)

- the left operand has qualified or unqualified arithmetic type
and the right has arithmetic type;

- the left operand has a qualified or unqualified version of a
structure or union type compatible with the type of the right;

- both operands are pointers to qualified or unqualified versions
of compatible types, and the type pointed to by the left has
all the qualifiers of the type pointed to by the right;

- one operand is a pointer to an object or incomplete type and
the other is a pointer to a qualified or unqualified version
of void, and the type pointed to by the left has all the
qualifiers of the type pointed to by the right;

- the left operand is a pointer and the right is a null pointer
constant; or

- the left operand has type _Bool and the right is a pointer.

Which of these alternatives is matched by fp = (void *)sc; ?
Any idea about what happens when a constraint is violated?

If the line in question was:

fp = (void(*)(void))sc; /* no 6.5.16.1 constraint violation */

the code would have invoked undefined behaviour and the quote from J.5.7
would have explained why such code *may* work on *certain*
implementations (still without giving it *any* legitimation).

It doesn't hurt to get a clue before posting irrelevant quotes from the
standard!

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de

Nov 13 '05 #9
Xenos <do**********@spamhate.com> scribbled the following:
Why is everyone in these newsgroups so friggin nasty and mean? This is why
usenet has gone to crap and it is now virtually useless as a mechanism for a
newby to get any kind of help.
1) That's Dan Pop. He's the nastiest guy around here. We others are
a little friendlier. A *little*.
2) Don't top-post, please. And try to trim quotes.
3) We have to be nasty sometimes to preserve proper topicality.
"Dan Pop" <Da*****@cern.ch> wrote in message
news:bg**********@sunnews.cern.ch...


(snip a very long bit of text that Xenos didn't bother to comment on,
but felt it was worth it to include nonetheless)
It doesn't hurt to get a clue before posting irrelevant quotes from the
standard!


(snip Dan Pop's signature, which is merely superfluous baggage in quoted
replies)

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"That's no raisin - it's an ALIEN!"
- Tourist in MTV's Oddities
Nov 13 '05 #10
Joona I Palaste wrote:
3) We have to be nasty sometimes to preserve proper topicality.


You don't feel it's possible to preserve topicality pleasantly?

--
|_ CJSonnack <Ch***@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|___ ____________________|
Nov 13 '05 #11
Programmer Dude <cj*******@mmm.com> scribbled the following:
Joona I Palaste wrote:
3) We have to be nasty sometimes to preserve proper topicality.
You don't feel it's possible to preserve topicality pleasantly?


I did say "sometimes".

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"As we all know, the hardware for the PC is great, but the software sucks."
- Petro Tyschtschenko
Nov 13 '05 #12
Xenos wrote:

[WRT one of Dab Pop's replies]
Why is everyone in these newsgroups so friggin nasty and mean?
Why is the sun made of green cheese?

Not everyone here is "friggin nasty and mean", despite the temptations.
This is
why usenet has gone to crap and it is now virtually useless as a mechanism
for a newby to get any kind of help.


Well, I disagree. Places in usenet also turn to crap because conversations
are allowed to stray arbitrarily off-topic, core competance gets lost,
and the noise dominates the signal. For a technical newsgroup, this is
even *less* helpful to newbies.

Dan's reply was his normal model of politeness and decorum, but Dan
is not "everyone", and his technical content, if he's not furiously
trying to wriggle out of a corner or taking a joke too seriously [1],
is bang-on. Given that newsgroups are exchange-of-text, not face-to-face,
I'd rather have accurate information than not.

[1] That's my reading; it's *only* my opinion.

--
Chris "electric hedgehog" Dollin
C FAQs at: http://www.faqs.org/faqs/by-newsgrou...mp.lang.c.html
C welcome: http://www.angelfire.com/ms3/bchambl...me_to_clc.html
Nov 13 '05 #13
# Why is everyone in these newsgroups so friggin nasty and mean?

"Assholes do vex me"
Robin Williams

--
Derk Gwen http://derkgwen.250free.com/html/index.html
You hate people.
But I love gatherings. Isn't it ironic.
Nov 13 '05 #14
In <bg*************@news.t-online.com> Jens Schicke <dr******@gmx.de> writes:
Jack Klein <ja*******@spamcop.net> wrote:
BTW: main doesn't need to be a function either :)
We discuss the C language here. If you want to spout bullsh*t, go
somewhere else.
long long main = 0xC300000000B8; // int main(void) { return 0; }


If you think the above is C, you are brain-damaged.


# cat foo.c
int main = 0xC3C031;
# gcc -W -Wall -pedantic -ansi foo.c
foo.c:1: warning: `main' is usually a function
#

To me it looks like valid ansi-C,


If it's valid ANSI C, please explain to the rest of us its meaning,
according to the ANSI C standard. What can I expect from this program
when running it on a SPARC/Solaris or POWER/AIX system?

Let's see:

mentor:~/tmp 8> uname -a
SunOS mentor 5.8 Generic_108528-11 sun4u sparc
mentor:~/tmp 9> cat test.c
int main = 0xC3C031;
mentor:~/tmp 10> gcc -Wall test.c
test.c:1: warning: `main' is usually a function
mentor:~/tmp 11> ./a.out
Illegal instruction (core dumped)
at least the gcc thinks of it as such...


On the contrary, gcc has clearly expressed its doubts.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #15
Programmer Dude <cj*******@mmm.com> wrote:
Joona I Palaste wrote:
We have to be nasty sometimes to preserve proper topicality.

You don't feel it's possible to preserve topicality pleasantly?


I did say "sometimes".


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
Nov 13 '05 #16
Programmer Dude <cj*******@mmm.com> wrote in message news:<3F***************@mmm.com>...
Joona I Palaste wrote:
We have to be nasty sometimes to preserve proper topicality.

You don't feel it's possible to preserve topicality pleasantly?


I did say "sometimes".


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
Nov 13 '05 #17
Richard Bos wrote:
> We have to be nasty sometimes to preserve proper topicality.

You don't feel it's possible to preserve topicality pleasantly?

I did say "sometimes".


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.


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.

--
|_ CJSonnack <Ch***@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|___ ____________________|
Nov 13 '05 #18
In <3F***************@mmm.com> Programmer Dude <cj*******@mmm.com> writes:
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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #19
"Programmer Dude" <cj*******@mmm.com> wrote
Dan Pop wrote:
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.


So would breaking their arm. The problem is the side effects.
It certainly worked for me, back when I was a c.l.c newbie.


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.
Nov 13 '05 #20
Programmer Dude <cj*******@mmm.com> wrote:
Richard Bos wrote:
>> We have to be nasty sometimes to preserve proper topicality.
>
> You don't feel it's possible to preserve topicality pleasantly?

I did say "sometimes".

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.


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
Nov 13 '05 #21
In <3F***************@mmm.com> Programmer Dude <cj*******@mmm.com> writes:
Dan Pop wrote:
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.


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.
It certainly worked for me, back when I was a c.l.c newbie.


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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #22
"Java Böy" <ja*****@zapo.net> wrote in message news:<bg**********@adenine.netfront.net>...
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.
fp();
And this calls the function.
}


[snip]
Nov 13 '05 #23
Richard Bos wrote:
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. (-:

--
|_ CJSonnack <Ch***@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL |
|_____________________________________________|___ ____________________|
Nov 13 '05 #24


Dan Pop wrote:
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
Nov 13 '05 #25
Programmer Dude <cj*******@mmm.com> wrote:
Richard Bos wrote:
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.


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
Nov 13 '05 #26

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: R.G. Vervoort | last post by:
I am using a javafunction (onclick in select) in which i am calling a function in php (thats why i send this to both php and javascript newsgroups). in the onclick i call the function...
2
by: Chris Michael | last post by:
Hello everybody, Newbie here. I've been working on this for the last two days and I can't figure out where this problem is. I think it's something so obvious, but I can't see it! OK, firstly...
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
3
by: Janross | last post by:
I'm having trouble with a query that's prohibitively slow. On my free-standing office computer it's fine (well, 2-4 seconds), but on the client's network, it takes at least 5 minutes to run. ...
9
by: Kishor | last post by:
Hi all, I am Using VB.Net for developing my application. I am now needed help. In this project I have to execute some function, but I cannot call them directly using function name, I wanted to...
9
by: Bill Borg | last post by:
Hello, I call a function recursively to find an item that exists *anywhere* down the chain. Let's say I find it five layers deep. Now I've got what I need and want to break out of that whole...
1
by: Falko Wagner | last post by:
Hi there, I am currently translating a VB 6.0 application to .NET and have the following problem: The data structure I need to pass to a DLL function call has a structure variable inside its...
11
by: yangsuli | last post by:
i want to creat a link when somebody click the link the php script calls a function,then display itself :) i have tried <a href=<? funtion(); echo=$_server ?>text</a> but it will call the...
2
by: WGW | last post by:
Hello all, I need another set of eyes cause it just isn't working, no matter how identical I make it. The initRotator function works when called by itself, but when adding another function, only the...
2
by: szimek | last post by:
Hi! In an app which I'm trying to fix to work with FF there's a lot of code like eval("function_name();"). I remember that there's some way to call global functions using window object, but I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.