Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C problem

Name: Anonymous 2007-04-10 13:40 ID:YqaTtdxC


main() {
"example";
}


What happends here? Is the string example pushed somewhere?

Name: Anonymous 2007-04-10 13:51 ID:U1arqosk

constant character array is being created, placed in memory, then the program exits and the c-string is destroyed.

Name: Anonymous 2007-04-10 13:55 ID:HxyeUmnk

I can't believe that compiles.

Also, I disagree with >>2. A simple strings disproves it.

Name: Anonymous 2007-04-10 13:57 ID:U1arqosk

>>3
It definitely compiles.

| A simple strings disproves it.
huh? How do i english?

Name: Anonymous 2007-04-10 13:59 ID:bft/vtSP

Compiled with -ggdb.
08048324 <main>:
main() {
 8048324:       8d 4c 24 04             lea    0x4(%esp),%ecx
 8048328:       83 e4 f0                and    $0xfffffff0,%esp
 804832b:       ff 71 fc                pushl  0xfffffffc(%ecx)
 804832e:       55                      push   %ebp
 804832f:       89 e5                   mov    %esp,%ebp
 8048331:       51                      push   %ecx
"example";
}
 8048332:       59                      pop    %ecx
 8048333:       5d                      pop    %ebp
 8048334:       8d 61 fc                lea    0xfffffffc(%ecx),%esp
 8048337:       c3                      ret
 8048338:       90                      nop
 8048339:       90                      nop
 804833a:       90                      nop
 804833b:       90                      nop
 804833c:       90                      nop
 804833d:       90                      nop
 804833e:       90                      nop
 804833f:       90                      nop

Name: Anonymous 2007-04-10 14:02 ID:U1arqosk

>>3
Oh man you got pwn3d. Suck it, bitch.

Name: Anonymous 2007-04-10 14:05 ID:bft/vtSP

>>6
In what way?  My listing proves his argument.

Here's the same, without the string there.  The assembly is the same.
08048324 <main>:
main() {
 8048324:       8d 4c 24 04             lea    0x4(%esp),%ecx
 8048328:       83 e4 f0                and    $0xfffffff0,%esp
 804832b:       ff 71 fc                pushl  0xfffffffc(%ecx)
 804832e:       55                      push   %ebp
 804832f:       89 e5                   mov    %esp,%ebp
 8048331:       51                      push   %ecx
}
 8048332:       59                      pop    %ecx
 8048333:       5d                      pop    %ebp
 8048334:       8d 61 fc                lea    0xfffffffc(%ecx),%esp
 8048337:       c3                      ret

Name: Anonymous 2007-04-10 14:09 ID:HxyeUmnk

>>6
Did I? Did you actually read >>5?

Name: Anonymous 2007-04-10 14:09 ID:U1arqosk

>>7
In that the program did compile.

As for the c-string, what actually does happen, then? The compiler simply skips that line? That doesn't seem right.

Name: Anonymous 2007-04-10 14:13 ID:HxyeUmnk

In that the program did compile.
Hey, nub, how am I supposed to run strings on something that didn't compile? May I suggest you type "man strings"?

Name: Anonymous 2007-04-10 14:15 ID:U1arqosk

>>10
| Hey, nub, how am I supposed to run strings on something that didn't compile?

Um it did compile.

Name: Anonymous 2007-04-10 14:19 ID:zmz41NYO

>>11
Exactly.

Name: Anonymous 2007-04-10 14:26 ID:U1arqosk

| I can't believe that compiles.

Oh, that sentence confused me. You were expressing your disbelief at the program compiling. I thought you were asserting that it didn't compile (ie you wouldn't believe that it compiles).

In light of this new information, i've decided that you no longer need to suck it.

The question still remains, though. WTF is going on in that program.

Name: Anonymous 2007-04-10 14:27 ID:bft/vtSP

R-R-RETARDS !!

Name: Anonymous 2007-04-10 14:34 ID:L8x1jHHz

Idiots. It evaluates to TRUE

Name: Anonymous 2007-04-10 14:44 ID:YqaTtdxC

>>3
OP here i understood what's going on (finally)
strings is a unix command, and when i used it on the compiled program the string "example" didn't appear anywhere, so the compiler propably optimizes it or does something tricky i don't know.

Name: Anonymous 2007-04-10 15:17 ID:U1arqosk

>>16
That's what I was thinking. Because, according to my debugger, this program skips the "if" statement:
#include <iostream>
using namespace std;

int main()
{
    if("What happens?")
    {
        "Nothing";
    }
    return 0;
}

While this one doesn't:

#include <iostream>
using namespace std;

int main()
{
    if("What happens?")
    {
        cout << "Nothing";
    }
    return 0;
}

Which makes me think the optimizer is being tricky.

Name: Anonymous 2007-04-10 15:20 ID:53feAzLV

>>17
Why are you using C++?

Name: Anonymous 2007-04-10 15:27 ID:S1SMHemO

>>18
He wanted to use C with magic, but also wanted a proper compiled language.  He's kind of like a Java fence-sitter, only I can respect him just a little more.

Name: Anonymous 2007-04-13 18:58 ID:tUwmNyrc

lazy evaluation? in my C?

Name: Anonymous 2007-04-13 19:21 ID:zHrwNJpp

Tricky? It's standard issue optimization. A constant string evaluates to a pointer and a pointer is just an integer. The pointer is obviously not NULL which means it's an integer that is not equal to 0, in other words it evaluates to true and is no different from "if (1)". Also cout::operator<< is a function so the compiler cannot optimize it away since it may have side-effects (and it does, it writes to stdout). A statement that is a constant expression doesn't do anything so it can be thrown away.

Name: Anonymous 2007-04-14 1:49 ID:nchVaC2Y

"What happens?" and "Nothing" are stored as static strings; so in essence, you might as well say:

const char *s1 = "What happens?";
const char *s2 = "Nothing";

s1 ? s2 : (void) 0;

There is no effect here no matter what s1 or s2 are; even if s1 is null, the resultant statement of s2 does not constitute an action; and, if s1 is not null, then (void) 0 also has no effect. The statement is thus easily reduced to "Do Nothing" by any competent compiler.

Name: Anonymous 2007-04-14 3:30 ID:u0fPVPwq

>>22
Be careful, you are dealing with an idiot that doesn't understand strings and you put "Do Nothing" in quotes.  He's probably trying to figure out how to output "Do Nothing" using his "What happens?" and "Nothing" strings in an if statement right now.

Name: Anonymous 2007-04-14 4:05 ID:2XPfo9dZ

retards.hs:3:0:
    Couldn't match expected type `IO a' against inferred type `[Char]'
    In the first argument of `GHC.TopHandler.runMainIO', namely `main'
    When checking the type of the main function `main'

Name: Anonymous 2007-04-14 5:13 ID:KpofLTGp

>>22
LOL fuckind FAIL
You should REALLY listen to what EXPERT PROGRAMMERS have to say and stop acting like a fool.

Name: Anonymous 2009-03-06 9:16

chain 1 Valid WinRAR.

Name: Sgt.Kabu휴ᅱkiman䱀矚 2012-05-29 0:06

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List