int f(int x)
{
static int b = 0; static int s = 0;
int a = 0, t;
if (!s) {
a = b; b = x;
} else {
a = x; t = b;
do {
a ^= b;
b = (a^b) & b;
b <<= 1;
} while (b);
b = t;
}
s = (s+1) % 2;
return a;
}
int g(int i, int *j)
{
*j = i;
i = (int) putchar;
if (*j == (48 << 1))
__asm volatile (
"movl 8(%ebp),%eax;"
"leave;"
"ret"
);
return (int) puts;
}
void h(int i)
{
int b;
q = (void(*)()) g(i++[data],&b);
for (f(b);*(data+i)!=b;++i,f(b))
q(f(i[data])%0xff);
}
void sh(int s)
{
if (s == 010)
((void(*)())g(s,&s))("F");
longjmp(p,s);
}
int main(void)
{
int base, addr = 0xffffffff, offs = 16;
int a = 11, b = 32, i = 25;
int s = 8, t = 1, u = 4;
((void(*)()) data)(&a,&b);
((void(*)()) data)(&b,&t);
((void(*)()) data)(&t,&s);
addr ^= a;
a ^= addr;
addr ^= a;
base = ((int(*)())data+addr)();
if (a == -1)
goto over;
puts("A");
I hope you do realize this code is as it says: `undefined'. The output is not guaranteed to be the same for all people. Can you comprehend that simple statement?
Name:
Anonymous2012-01-11 14:37
>>86
>same compiler on Intel architecture
Its not going to be different, retard
Name:
Anonymous2012-01-11 14:37
>>86
No they can't, I have tried.
I'm the person he thinks you are now.
Just ask them show you where __asm is defined in any of the C standards.
>>87
There is no way you can guarantee that, that is due to the undefined behavior.
Name:
Anonymous2012-01-11 14:39
>>87-88
For fuck sake, why do you think it is reserved? That's right, to inline assembly. God you are retarded.
Name:
Anonymous2012-01-11 14:39
OP, just go back to /g/.
Name:
Anonymous2012-01-11 14:40
>>90
There is. Same compiler for same architecture will produce same machine code -> same result. It isn't undefined behaviour. __asm doesn't result in undefined behaviour you fucking moron, __asm inlines assembly.
Name:
Anonymous2012-01-11 14:41
>>87 HURR DURR WE ALL HAVE INTELS AND THE SAME PROCESSOR. HOW DO I PORTABLE CODE. >>88
see >>74
Your code is undefined, stop acting as if it's not.
Some people can't even compile your code even with the commands you give because it is not standard.
Name:
Anonymous2012-01-11 14:41
>>91
Read the standard you fucking retard. Any identifier that starts with two leading underscores is reserved, there is nothing in the standard that defines what __asm does or even mentions assembly.
__asm isn't part of C you fucking moron now fuck off back to /g/ with your retarded shit.
Name:
Anonymous2012-01-11 14:42
FIGHT FIGHT
Name:
Anonymous2012-01-11 14:43
K&R The C programming language, 2ed page 192. (apendix A)
The following identifiers are reserved for use as keywords (AS keywords[sic!]), and may not be used otherwise: [...]
Some implementations reserve the words fortran and asm.
It means that they ARE keywords. Which is VALID code, for some implementations of C. God you are retarded. Go back to scripting.
Name:
Anonymous2012-01-11 14:43
>>93
You don't understand, if it's undefined then you can't guarantee that it will produce the same code every time.
Name:
Anonymous2012-01-11 14:44
>>97
Which is VALID code, for some implementations of C.
Hey genius, did you notice the part of the doc that read "C extensions"? In other words, it's an extension of standard C.
Name:
Anonymous2012-01-11 14:48
>>101 USE THE COMPILER IN OP. God how autistic are you?
I don't use non-standard compilers.
Please take your shitty toy language subset of C back to the imageboards you dumb fuck.
Next time you come to /prog/ expecting us to do something for you don't fucking make obscure code that requires the download of a non-standard tool, We are not fucking hipsters that act like hackers all day by using undefined shitty code.
Name:
Anonymous2012-01-11 14:49
>>105
You can guarantee that GCC won't rely on undefined behavior to compile undefined behavior?
| Please take your shitty toy language subset of C
herp derp
| that requires the download of a non-standard tool
GCC is non-standard, wow. Just wow.
Name:
Anonymous2012-01-11 14:51
>>107
I never claimed it to be non-standard. But the faggots here are all herp derp its non-standard derp instead of just not responding. Fucking obsessive-compulsive disorder
int f(int x)
{
static int b = 0; static int s = 0;
int a = 0, t;
if (!s) {
a = b; b = x;
} else {
a = x; t = b;
do {
a ^= b;
b = (a^b) & b;
b <<= 1;
} while (b);
b = t;
}
s = (s+1) % 2;
return a;
}
int g(int i, int *j)
{
*j = i;
i = (int) putchar;
if (*j == (48 << 1))
__asm volatile (
"movl 8(%ebp),%eax;"
"leave;"
"ret"
);
return (int) puts;
}
void h(int i)
{
int b;
q = (void(*)()) g(i++[data],&b);
for (f(b);*(data+i)!=b;++i,f(b))
q(f(i[data])%0xff);
}
void sh(int s)
{
if (s == 010)
((void(*)())g(s,&s))("F");
longjmp(p,s);
}
int main(void)
{
int base, addr = 0xffffffff, offs = 16;
int a = 11, b = 32, i = 25;
int s = 8, t = 1, u = 4;
((void(*)()) data)(&a,&b);
((void(*)()) data)(&b,&t);
((void(*)()) data)(&t,&s);
addr ^= a;
a ^= addr;
addr ^= a;
base = ((int(*)())data+addr)();
if (a == -1)
goto over;
puts("A");
if (!(s = setjmp(p))) {
q = (void(*)()) g(0x30, &a);
q(data + a + i);
s = a / (b-1);
puts("B");
} else if (s == 0xb) {
puts("C");
((int(*)(int)) data+addr+(offs/2))(base);
} else {
puts("D");
*((int*) base+s) = 0xffffffff;
}
puts("E");
return 1;
}
[ Wed Jan 11 02:52:09 ]
[ @ ~/fhost/prog/C ] $ gcc -O0 -m32 nstd.c
nstd.c: In function ‘g’:
nstd.c:49: warning: cast from pointer to integer of different size
nstd.c:56: warning: cast from pointer to integer of different size
nstd.c: In function ‘h’:
nstd.c:62: warning: cast to pointer from integer of different size
nstd.c: In function ‘sh’:
nstd.c:70: warning: cast to pointer from integer of different size
nstd.c: In function ‘main’:
nstd.c:98: warning: cast to pointer from integer of different size
nstd.c:107: warning: cast to pointer from integer of different size
[ Wed Jan 11 02:55:03 ]
[ @ ~/fhost/prog/C ] $ ./a.out
Segmentation fault