473,320 Members | 1,821 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,320 software developers and data experts.

obfuscated

Hi all,

can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you
1) what is this under score stuff inside main parenthesis?
2) what does this --_ mean in the initialization condition of for
loop
3) what is the role of this operator _ (unary minus i presume) in
putchar

Oct 10 '06 #1
42 2265

<aa*****@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi all,

can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you
Not without seeing all of it.
>

1) what is this under score stuff inside main parenthesis?
2) what does this --_ mean in the initialization condition of for
loop
3) what is the role of this operator _ (unary minus i presume) in
putchar
No, it's not an operator at all. It's probably a macro whose
definition you're not showing us.

-Mike
Oct 10 '06 #2
aa*****@gmail.com wrote:
Hi all,

can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you

I'll bite. I might be wrong, but I'll bite.
1) what is this under score stuff inside main parenthesis?
It is an illegal (I presume) reference to something like argc. It is
similar to "main(int _)", but very non-standard.

I expect for those compilers that accept this will set "_" to 1 before
we visit the for loop.
2) what does this --_ mean in the initialization condition of for
loop
It predecrements the C identifier "_".
3) what is the role of this operator _ (unary minus i presume) in
putchar
It is not an operator. It is equivalent in ways that count (standard or
not) to "int _".

So, we loop through the char array, getting the _th item in the array,
subtracting 1 and printing the char we get. I suppose this presumes
ASCII collation.
Oct 10 '06 #3

aa*****@gmail.com wrote:
Hi all,

can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you

easy. Underscore is an allowed character in an identifier. main(_)
declares it as a parameter in place of argc. argc is 1, so if yo
decrement it, it starts out at zero.
That "J!... " string is just "I love you" with 1 added to each
character.

>

1) what is this under score stuff inside main parenthesis?
2) what does this --_ mean in the initialization condition of for
loop
3) what is the role of this operator _ (unary minus i presume) in
putchar
Oct 10 '06 #4
Clever Monkey wrote:
aa*****@gmail.com wrote:
>Hi all,

can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you

I'll bite. I might be wrong, but I'll bite.
> 1) what is this under score stuff inside main parenthesis?
It is an illegal (I presume) reference to something like argc. It is
similar to "main(int _)", but very non-standard.

I expect for those compilers that accept this will set "_" to 1 before
we visit the for loop.
(Depending on how this code is run, of course. Try running the
executable with arguments and see what happens...)
Oct 10 '06 #5
Mike Wahler wrote:
<aa*****@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>Hi all,

can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you

Not without seeing all of it.
That /is/ all of it.
> 1) what is this under score stuff inside main parenthesis?
2) what does this --_ mean in the initialization condition of for
loop
3) what is the role of this operator _ (unary minus i presume) in
putchar

No, it's not an operator at all. It's probably a macro whose
definition you're not showing us.
It's the first (and only) argument to `main`. The program has to
be run with no arguments (each argument will ignore another
leading output character, that is if the undefined behaviour [1]
doesn't lead to metapsychic meltdown or penguins at Southend).

It's a bit obvious, really. If it weren't for Yet More Undefined
Behaviour, `_++["J!Mpwf!Zpv\1"]+_` would be better [2], with
appropriate adjustments to the string.

[1] I assume undefined behaviour because `main` wasn't declared in
one of the Two Allowed Ways. And of course it relies on ascii
character codes.

[2] For values of `better` that are ... um ... er ...

--
Chris "Essen -9 and counting" Dollin
Nit-picking is best done among friends.

Oct 10 '06 #6

aa*****@gmail.com wrote:
Hi all,

can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you
1) what is this under score stuff inside main parenthesis?
2) what does this --_ mean in the initialization condition of for
loop
3) what is the role of this operator _ (unary minus i presume) in
putchar
'_' is an argument of main, which is int; '--_' means decrease '_'
first.

The argument of putchar() can be rewritten as

("J!Mpwf!Zpv\1"[_++] )-1

, which is a char in the string "J!Mpwf!Zpv\1".

Oct 10 '06 #7
<aa*****@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi all,

can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you
1) what is this under score stuff inside main parenthesis?
2) what does this --_ mean in the initialization condition of for
loop
3) what is the role of this operator _ (unary minus i presume) in
putchar
All right, let's start:
the '_' identifier is used instead of the more well known argc.
Also, the a[1]=1[a] idiom is used.
So, let's
change the program to a more readable version:

main(int argc) {
for(
--argc;
putchar( "J!Mpwf!Zpv\1"[argc++] -1);
) ;
}

well, not much more readable, but now we can understand it:
argc has the value 1 when the program starts, so, when the
for starts, argc will be 0.

Now, while the putchar("...") does not return 0, the loop
will be executed each time and the value of argc will be
increased. And, considering that : J-1 = I, !-1=' '(space),
M-1 = L etc you see how I Love you is printed.

Last point: Why does the loop stop ? Because '\1' - 0 =0,
so, putchar will return 0 and the loop will exit :)

Serafeim Papastefanos


Oct 10 '06 #8

Mike Wahler wrote:
<aa*****@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi all,

can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you

Not without seeing all of it.


1) what is this under score stuff inside main parenthesis?
2) what does this --_ mean in the initialization condition of for
loop
3) what is the role of this operator _ (unary minus i presume) in
putchar

No, it's not an operator at all. It's probably a macro whose
definition you're not showing us.

-Mike
i am not hiding any macro definition
i actually got this question from my friend which was as follows::

The following code prints "I LOVE YOU".

main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

Avoid the use of digit 1 in above code to print the same output.
Keep in mind not to use direct output text in the code :-)

Oct 10 '06 #9
Mike Wahler wrote:
<aa*****@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>Hi all,

can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you

Not without seeing all of it.
That's all of it. It's not all that strange.
The mapping of the data to the output is obvious.

_ gets the argc value. It gets decremented. It then is used as an
array index (because n[a] is equivalent to a[n]), and each element of
the array is decremented by one. When it gets to '\0', putchar returns
0 and the for loop ends.

Oct 10 '06 #10
Clever Monkey wrote:
So, we loop through the char array, getting the _th item in the array,
subtracting 1 and printing the char we get. I suppose this presumes
ASCII collation.
Shouldn't a non-ASCII implementation do the right thing, where 'b' -1 =
'a', regardless of the inner details?
Oct 10 '06 #11
jmcgill <jm*****@email.arizona.eduwrote:
Clever Monkey wrote:
So, we loop through the char array, getting the _th item in the array,
subtracting 1 and printing the char we get. I suppose this presumes
ASCII collation.

Shouldn't a non-ASCII implementation do the right thing, where 'b' -1 =
'a', regardless of the inner details?
No. Read the Standard. Only '0'...'9' are required to be subsequent. The
rest need not, and often _but not always_ is subsequent.

Richard
Oct 10 '06 #12
Aarklon posted:
main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

(1) If we replace the underscore object name with "i", then we get:

main(i) {for(--i;putchar(i++["J!Mpwf!Zpv\1"]-1););}
(2) If we make explicit the implicit int:

int main(int i) {for(--i;putchar(i++["J!Mpwf!Zpv\1"]-1););}
(3) If we put in white space to make things prettier:

int main(int i)
{
for( --i; putchar(i++["J!Mpwf!Zpv\1"]-1); ) ;
}
(4) If we take "i" out of the loop, and then change it to a "while" loop:

int main(int i)
{
--i;

while( putchar(i++["J!Mpwf!Zpv\1"]-1); );
}
(5) If we change "index[array]" to "array[index]", then we have:

int main(int i)
{
--i;

while( putchar( "J!Mpwf!Zpv\1"[i++] - 1) );
}
(6) If we take the take the string out of the loop to make it clearer:

int main(int i)
{
char const str[] = "J!Mpwf!Zpv\1";

--i;

while (putchar(str[i++] - 1));
}

Armed with the knowledge that "putchar" returns the char it prints, we can
see that we are iterating through each character of the string, subtracting
one from it, then printing it.

The code is non-portable as it makes the unfounded presumption that:

'J' == 'I'+1

Also, I'm not sure if that's a valid signature for "main".

--

Frederick Gotham
Oct 10 '06 #13
Clever Monkey wrote:
aa*****@gmail.com wrote:
>Hi all,

can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you

I'll bite. I might be wrong, but I'll bite.
> 1) what is this under score stuff inside main parenthesis?
It is an illegal (I presume) reference to something like argc. It is
similar to "main(int _)", but very non-standard.
Actually, the function definition form
foo(arg) {}
Is entirely legal and standard C89 since C89 still allows implicit int
and old K&R style function definitions. The problem is that main takes 0
or 2 arguments, not one. This could be fixed by changing it to

main(_,__)char**__;{for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}
which still keeps it obfusticated.

You can get C99 compliance with
#include<stdio.h>
int main(_,__)int
_;char**__;{for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}
I expect for those compilers that accept this will set "_" to 1 before
we visit the for loop.
<snip>

Unless the user supplies parameters or the environment chooses not to
pass something as the "program name".
--
Flash Gordon
Oct 10 '06 #14
Flash Gordon wrote:
Clever Monkey wrote:
>aa*****@gmail.com wrote:
>> can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you

1) what is this under score stuff inside main parenthesis?
It is an illegal (I presume) reference to something like argc. It is
similar to "main(int _)", but very non-standard.

Actually, the function definition form
foo(arg) {}
Is entirely legal and standard C89 since C89 still allows implicit int
and old K&R style function definitions. The problem is that main takes 0
or 2 arguments, not one. This could be fixed by changing it to

main(_,__)char**__;{for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}
which still keeps it obfusticated.
Sure. This is what I meant by "non-standard", since the main() is
malformed and incorrect with respect to the standard. I do understand
that this is a _mostly_ legal function definition; just not for the
function main(). Note my reference to "argc", above.

Furthermore, wasn't there just a thread here about the use of "_" and
"__" being forbidden by the standard under most circumstances? I
suppose an identifier that consists only of these characters would be
contrary to that rule, as well.

Again, this does not speak to the OP, but it indicates that many things
about "main(_)" are probably wrong, regardless of the fact that main()
can be treated just like another function in many cases and that the
default type for untyped identifiers is int.
Oct 10 '06 #15
aa*****@gmail.com wrote:
Hi all,

can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you
It doesn't produce that output. The L and Y are capitalised.

If you supply arguments to the program, one letter is lost from the
beginning for each argument you supply. If you supply more than 10
arguments, the program outputs garbage until a 1 byte is found in memory
or the program attempts to read an invalid address and is terminated.
C:\docs\prog\c>type aarklon.c
#include <stdio.h>
main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

C:\docs\prog\c>tcc aarklon.c
Turbo C Version 2.01 Copyright (c) 1987, 1988 Borland International
aarklon.c:
Turbo Link Version 2.0 Copyright (c) 1987, 1988 Borland International

Available memory 394258

C:\docs\prog\c>aarklon 1 2 3 4 5 6 7 8 9 0 1
↕☺☺♥♦♣‼¶♦↕â–*§♦►☺â–*â–*â –*â–*â–*â–*â–*â–*â–*â–*â–*â–*â–*♦♦â–*â–*â–*â–* â–*â–*â–*â–*â–*â–*â–*â–*â–*â–*â–*â–*♫â–*"☺â–*â ™«â–*â–*â–*â–*↕â–*â–*☺☺♦♫☺â–*â–*â–*↕ â–*â–*â–*â–*â–*â–*â–*â–*
"â–*â–*â–*â–*"â–*↕â–* z☺z☺z☺ ☼ ☺ ‼☺

--
Simon.
Oct 10 '06 #16

Frederick Gotham wrote:
The code is non-portable as it makes the unfounded presumption that:

'J' == 'I'+1

Ah yes, any computers out there using the 5-bit Baudot code are going
to print complete gibberish.

Seriously, in IBM EBCDIC, the letters are not contiguous, due to it
being derived from BCD card codes, which as everybody knows, had nine
rows, so the letters are in groups of nine, with seven codes in between
to pad to the next multiple of 16.

But due to pure chance, most of the letters in this phrase are
comfortably away from the abrupt jumps. The only problem is with the
initial "J", which one less than is "}".
Also space is not just before exclamation point, Ampersand is. Also
the ending period gets messed up.

So in EBCDIC it will print out:

}&love&you|

Oct 10 '06 #17
Ancient_Hacker posted:
Ah yes, any computers out there using the 5-bit Baudot code are going
to print complete gibberish.

Exactly (assuming Baudot code has at least 3 unused bits).

Seriously, in IBM EBCDIC, the letters are not contiguous, due to it
being derived from BCD card codes, which as everybody knows, had nine
rows, so the letters are in groups of nine, with seven codes in between
to pad to the next multiple of 16.

Your use of "Seriously" is not necessary here at comp.lang.c, nor is it even
necessary to provide an example (although I'm glad you did :) ). All we need
to hear is "The Standard doesn't impose such a restriction" and we're bought.

--

Frederick Gotham
Oct 10 '06 #18
Clever Monkey wrote:
Flash Gordon wrote:
>Clever Monkey wrote:
>>aa*****@gmail.com wrote:
can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you

1) what is this under score stuff inside main parenthesis?
It is an illegal (I presume) reference to something like argc. It is
similar to "main(int _)", but very non-standard.

Actually, the function definition form
foo(arg) {}
Is entirely legal and standard C89 since C89 still allows implicit int
and old K&R style function definitions. The problem is that main takes
0 or 2 arguments, not one. This could be fixed by changing it to

main(_,__)char**__;{for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}
which still keeps it obfusticated.
Sure. This is what I meant by "non-standard", since the main() is
malformed and incorrect with respect to the standard. I do understand
that this is a _mostly_ legal function definition; just not for the
function main(). Note my reference to "argc", above.
OK, then we are in agreement about what is and is not valid.
Furthermore, wasn't there just a thread here about the use of "_" and
"__" being forbidden by the standard under most circumstances? I
suppose an identifier that consists only of these characters would be
contrary to that rule, as well.
You are right, I should not have used __. Perhals _l or _L would be
sufficiently obscure. That will teach me to rely on memory for a rule
like this. Normally I just don't start identifiers with an _ even where
it would be legal.
Again, this does not speak to the OP, but it indicates that many things
about "main(_)" are probably wrong, regardless of the fact that main()
can be treated just like another function in many cases and that the
default type for untyped identifiers is int.
Well, the _ on its own is acceptable as an identifier as long as it is
not a file scope identifier which it isn't.
--
Flash Gordon
Oct 10 '06 #19
On Tue, 10 Oct 2006 08:41:07 -0700, in comp.lang.c , jmcgill
<jm*****@email.arizona.eduwrote:
>Clever Monkey wrote:
>So, we loop through the char array, getting the _th item in the array,
subtracting 1 and printing the char we get. I suppose this presumes
ASCII collation.

Shouldn't a non-ASCII implementation do the right thing, where 'b' -1 =
'a', regardless of the inner details?
No, this isn't required by the Standard, and indeed realworld
implementations will break this assumption (think non-english
character sets, or EBCDIC or whatever)
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Oct 10 '06 #20
Mark McIntyre wrote:
No, this isn't required by the Standard, and indeed realworld
implementations will break this assumption (think non-english
character sets, or EBCDIC or whatever)
I was thinking of those, and I was under the impression that lexical
ordering was guaranteed, but I guess not.

Oh well, these obfuscated code examples are rarely meant to be good
examples of strictly conforming, portable C. Likewise, ACM programming
contest entries have to be just good enough to compile and run once on
the target platform :-)
Oct 10 '06 #21
aa*****@gmail.com wrote:
i am not hiding any macro definition
i actually got this question from my friend which was as follows::

The following code prints "I LOVE YOU".

main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

Avoid the use of digit 1 in above code to print the same output.
Keep in mind not to use direct output text in the code :-)
No problem, I replaced the "1" by "2":

int main(_,_o){for(_^=_;putchar(_++["Wlfgdklgf\"@gjctkmwp\b\2"]^2););}

Also it works with command line arguments. It still requires an ASCII
character set.

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Oct 10 '06 #22

Thomas J. Gritzan wrote:
aa*****@gmail.com wrote:
i am not hiding any macro definition
i actually got this question from my friend which was as follows::

The following code prints "I LOVE YOU".

main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

Avoid the use of digit 1 in above code to print the same output.
Keep in mind not to use direct output text in the code :-)

No problem, I replaced the "1" by "2":

int main(_,_o){for(_^=_;putchar(_++["Wlfgdklgf\"@gjctkmwp\b\2"]^2););}
The data type of _o is wrong.
The main() function does not return a value.
Also it works with command line arguments. It still requires an ASCII
character set.
This should be portable to any system.

#include <stdio.h>
int _;
const char *__ =
"\117"
"\142"
"\146"
"\165"
"\163"
"\143"
"\141"
"\164"
"\145"
"\40"
"\143"
"\157"
"\162"
"\162"
"\145"
"\143"
"\164"
"\154"
"\171"
"\54"
"\40"
"\160"
"\154"
"\145"
"\141"
"\163"
"\145"
"\56"
"\n"
;
int main() ??<for (; putchar(_++ ??(__ ??)););return 0;??>
--
Thomas
http://www.netmeister.org/news/learn2quote.html
Oct 10 '06 #23

Ancient_Hacker wrote:
aa*****@gmail.com wrote:
Hi all,

can anybody please explain why this code

main(_) {for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

is producing the output:: I love you


easy. Underscore is an allowed character in an identifier. main(_)
declares it as a parameter in place of argc. argc is 1, so if yo
decrement it, it starts out at zero.
That "J!... " string is just "I love you" with 1 added to each
character.
Of course, argc can be zero. There is no requirement in the C language
that argc is at least one and that argv[0] contains the program name.
It is possible for argc to be zero and argv[1] to be a null pointer.

1) what is this under score stuff inside main parenthesis?
2) what does this --_ mean in the initialization condition of for
loop
3) what is the role of this operator _ (unary minus i presume) in
putchar
Oct 10 '06 #24
dc*****@connx.com wrote:
Thomas J. Gritzan wrote:
>aa*****@gmail.com wrote:
>> i am not hiding any macro definition
i actually got this question from my friend which was as follows::

The following code prints "I LOVE YOU".

main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

Avoid the use of digit 1 in above code to print the same output.
Keep in mind not to use direct output text in the code :-)
No problem, I replaced the "1" by "2":

int main(_,_o){for(_^=_;putchar(_++["Wlfgdklgf\"@gjctkmwp\b\2"]^2););}

The data type of _o is wrong.
The main() function does not return a value.
>Also it works with command line arguments. It still requires an ASCII
character set.

This should be portable to any system.
[snip]

Still assumes an ASCII character set

--
Clark S. Cox III
cl*******@gmail.com
Oct 11 '06 #25
A couple simple changes has turned this into a broken compiler test.
GCC Passes:

dcorbit@DCORBIT64 /mingw
$ cat broke_o.c
??=include <stdio.h>
int _;
const char *__ =
"\117""\142""\146""\165"
"\163""\143""\141""\164"
"\145""\40""\143""\157"
"\162""\162""\145""\143"
"\164""\154""\171""\54"
"\40""\160""\154""\145"
"\141""\163""\145""\56""\n";
/??/
* Comment carefully *??/
/
int main() ??<for (; putchar(_++ ??(__ ??)););return 0;??>

dcorbit@DCORBIT64 /mingw
$ gcc -Wall -ansi -pedantic broke_o.c
broke_o.c:1:1: warning: trigraph ??= converted to #
broke_o.c:11:2: warning: trigraph ??/ converted to \
broke_o.c:12:22: warning: trigraph ??/ converted to \
broke_o.c:14:12: warning: trigraph ??< converted to {
broke_o.c:14:32: warning: trigraph ??( converted to [
broke_o.c:14:36: warning: trigraph ??) converted to ]
broke_o.c:14:50: warning: trigraph ??converted to }

dcorbit@DCORBIT64 /mingw
$ ./a
Obfuscate correctly, please.

dcorbit@DCORBIT64 /mingw
$

MS VC++ fails:
C:\mingw>cl /W4 /Ox broke_o.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42
for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

broke_o.c
broke_o.c(15) : fatal error C1071: unexpected end of file found in
comment

Oct 11 '06 #26

Clark S. Cox III wrote:
dc*****@connx.com wrote:
Thomas J. Gritzan wrote:
aa*****@gmail.com wrote:
i am not hiding any macro definition
i actually got this question from my friend which was as follows::

The following code prints "I LOVE YOU".

main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}

Avoid the use of digit 1 in above code to print the same output.
Keep in mind not to use direct output text in the code :-)
No problem, I replaced the "1" by "2":

int main(_,_o){for(_^=_;putchar(_++["Wlfgdklgf\"@gjctkmwp\b\2"]^2););}
The data type of _o is wrong.
The main() function does not return a value.
Also it works with command line arguments. It still requires an ASCII
character set.
This should be portable to any system.

[snip]

Still assumes an ASCII character set
Within a C source file, isn't ISO 646 character set assumed?
--
Clark S. Cox III
cl*******@gmail.com
Oct 11 '06 #27
dc*****@connx.com wrote:
Clark S. Cox III wrote:
>dc*****@connx.com wrote:
>>Thomas J. Gritzan wrote:
aa*****@gmail.com wrote:
i am not hiding any macro definition
i actually got this question from my friend which was as follows::
>
The following code prints "I LOVE YOU".
>
main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}
>
Avoid the use of digit 1 in above code to print the same output.
Keep in mind not to use direct output text in the code :-)
No problem, I replaced the "1" by "2":

int main(_,_o){for(_^=_;putchar(_++["Wlfgdklgf\"@gjctkmwp\b\2"]^2););}
The data type of _o is wrong.
The main() function does not return a value.

Also it works with command line arguments. It still requires an ASCII
character set.
This should be portable to any system.
[snip]

Still assumes an ASCII character set

Within a C source file, isn't ISO 646 character set assumed?
No.

--
Clark S. Cox III
cl*******@gmail.com
Oct 11 '06 #28
dc*****@connx.com writes:
Clark S. Cox III wrote:
>dc*****@connx.com wrote:
[snip]
This should be portable to any system.

[snip]

Still assumes an ASCII character set

Within a C source file, isn't ISO 646 character set assumed?
Certainly not. For example, EBCDIC-based systems are allowed and not
uncommon.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Oct 11 '06 #29
dc*****@connx.com wrote:
Of course, argc can be zero. There is no requirement in the C language
that argc is at least one and that argv[0] contains the program name.
It is possible for argc to be zero and argv[1] to be a null pointer.
----------------------------------------------^

Do you mean
it is possible for argc to be zero and argv[0] to be a null pointer/
--------------------------------------------^
?

#include <stdio.h>

int main(int argc, char **argv) {
if (argc == 0) {
puts(argv[1]); /* BOOM: accessing one past end of array */
}
puts(argv[argc+1]); /* BOOM: accessing one past end of array */
return 0;
}

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
Oct 11 '06 #30
Clark S. Cox III wrote:
dc*****@connx.com wrote:
Within a C source file, isn't ISO 646 character set assumed?

No.
Even if it where, characters in constants and literals get mapped to
the execution character set anyway.

--
Peter

Oct 11 '06 #31
dc*****@connx.com wrote:
It is possible for argc to be zero and argv[1] to be a null pointer.
Because you cannot necessarily rely on main(int, char**) being called
the way you expect? Or something else? I have never considered this
before. But obviously there's nothing very special about main.
Anything that can get the appropriate linkage can call it with whatever
stack it wants, right?
Oct 11 '06 #32
Pedro Graca said:
dc*****@connx.com wrote:
>Of course, argc can be zero. There is no requirement in the C language
that argc is at least one and that argv[0] contains the program name.
It is possible for argc to be zero and argv[1] to be a null pointer.
----------------------------------------------^

Do you mean
it is possible for argc to be zero and argv[0] to be a null pointer/
Yes, that's what he means. argv[argc] is NULL by definition.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 11 '06 #33
jmcgill said:
Mark McIntyre wrote:
>No, this isn't required by the Standard, and indeed realworld
implementations will break this assumption (think non-english
character sets, or EBCDIC or whatever)

I was thinking of those, and I was under the impression that lexical
ordering was guaranteed, but I guess not.
EBCDIC's okay with the ordering, but the alphabets are non-contiguous,
coming as they do in rows of ten on boundaries of sixteen.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 11 '06 #34
On Tue, 10 Oct 2006 14:51:32 -0700, in comp.lang.c , jmcgill
<jm*****@email.arizona.eduwrote:
>Mark McIntyre wrote:
>No, this isn't required by the Standard, and indeed realworld
implementations will break this assumption (think non-english
character sets, or EBCDIC or whatever)

I was thinking of those, and I was under the impression that lexical
ordering was guaranteed, but I guess not.
Probably doesn't work too well in any character set pertaining to
cyrillic, greek, chinese, arabic, hebrew, turkish, etc etc.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Oct 11 '06 #35
On Tue, 10 Oct 2006 20:19:14 -0700, in comp.lang.c , jmcgill
<jm*****@email.arizona.eduwrote:
>dc*****@connx.com wrote:
>It is possible for argc to be zero and argv[1] to be a null pointer.
the zeroth argument of main() is reserved for the program name, but an
implementation is not obligated to populate it. In an embedded
environment, there would be no need to.

Plus you can call main recursively in C.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Oct 11 '06 #36
Mark McIntyre wrote:
On Tue, 10 Oct 2006 14:51:32 -0700, in comp.lang.c , jmcgill
<jm*****@email.arizona.eduwrote:
>Mark McIntyre wrote:
>>No, this isn't required by the Standard, and indeed realworld
implementations will break this assumption (think non-english
character sets, or EBCDIC or whatever)
I was thinking of those, and I was under the impression that lexical
ordering was guaranteed, but I guess not.

Probably doesn't work too well in any character set pertaining to
cyrillic, greek, chinese, arabic, hebrew, turkish, etc etc.
All of those character sets still have lexical ordering of Latin letters
A to Z. They are almost always built on ASCII as a base and use the
characters with high bit set to encode all the other required characters
(sometimes in pairs or quads). This is the case with ISO-8859 series,
ISO-2022 series, EUC series, Shift-JIS, GB2312, GB18030, Big5,
Big5-HKSCS, etc.

As for lexical ordering of other alphabets in their own charsets, that
varies. Some languages don't even have a well-defined ordering. There
are several possible sort orders for Chinese characters (based on
radicals, pronunciation or number of strokes).

--
Simon.
Oct 11 '06 #37
On Thu, 12 Oct 2006 05:58:39 +1000, in comp.lang.c , Simon Biber
<ne**@ralmin.ccwrote:
>Mark McIntyre wrote:
>On Tue, 10 Oct 2006 14:51:32 -0700, in comp.lang.c , jmcgill
<jm*****@email.arizona.eduwrote:
>>Mark McIntyre wrote:

No, this isn't required by the Standard, and indeed realworld
implementations will break this assumption (think non-english
character sets, or EBCDIC or whatever)
I was thinking of those, and I was under the impression that lexical
ordering was guaranteed, but I guess not.

Probably doesn't work too well in any character set pertaining to
cyrillic, greek, chinese, arabic, hebrew, turkish, etc etc.

All of those character sets still have lexical ordering of Latin letters
A to Z
Chinese doesn't have any latin letters, its all pictures. Greek goes
abgde etc. Arabic doesn't use ASCII letters. etc.
>. They are almost always built on ASCII as a base
I fear you're thinking of national extensions to ISO-646.
>As for lexical ordering of other alphabets in their own charsets, that
varies. Some languages don't even have a well-defined ordering.
Absolutely.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Oct 11 '06 #38
Mark McIntyre wrote:
On Thu, 12 Oct 2006 05:58:39 +1000, in comp.lang.c , Simon Biber
<ne**@ralmin.ccwrote:
>Mark McIntyre wrote:
>>Probably doesn't work too well in any character set pertaining to
cyrillic, greek, chinese, arabic, hebrew, turkish, etc etc.
All of those character sets still have lexical ordering of Latin letters
A to Z

Chinese doesn't have any latin letters, its all pictures. Greek goes
abgde etc. Arabic doesn't use ASCII letters. etc.
I was referring to lexical ordering of Latin letters, not of other
characters. Chinese character sets DO have the full set of Latin
letters, alongside all the Chinese characters. So do Arabic character
sets. I am yet to see one that does not provide all the Latin letters
alongside the Arabic ones. And the Latin letters are in lexical order A
- Z. I said nothing about the ordering of the Arabic letters or Chinese
characters.
>. They are almost always built on ASCII as a base

I fear you're thinking of national extensions to ISO-646.
No, I'm referring to the specific character sets I mentioned.

--
Simon.
Oct 12 '06 #39
On Wed, 11 Oct 2006 06:14:35 +0000, Richard Heathfield
<in*****@invalid.invalidwrote:
jmcgill said:
Mark McIntyre wrote:
No, this isn't required by the Standard, and indeed realworld
implementations will break this assumption (think non-english
character sets, or EBCDIC or whatever)
I was thinking of those, and I was under the impression that lexical
ordering was guaranteed, but I guess not.

EBCDIC's okay with the ordering, but the alphabets are non-contiguous,
coming as they do in rows of ten on boundaries of sixteen.
s/ten/nine and eight (averaging 8.6overbar)/

But you do rhyme with 'seas of green', FWIW.
- David.Thompson1 at worldnet.att.net
Oct 23 '06 #40
On 10 Oct 2006 11:54:37 -0700, "Ancient_Hacker" <gr**@comcast.net>
wrote:
>
Frederick Gotham wrote:
The code is non-portable as it makes the unfounded presumption that:

'J' == 'I'+1


Ah yes, any computers out there using the 5-bit Baudot code are going
to print complete gibberish.
Not to mention that 'Baudot' (officially IA2, the International
(Teletype) Alphabet #2): does not have lowercase letters and several
punctuation or 'special' characters that are required in the basic
(minimum) execution character set; has codes for the digits that are
not consecutive as required, as well as being shift-state dependent
which may not be specifically prohibited but doesn't make sense for
the ctype.h functions.
Seriously, in IBM EBCDIC, the letters are not contiguous, due to it
being derived from BCD card codes, which as everybody knows, had nine
rows, so the letters are in groups of nine, with seven codes in between
to pad to the next multiple of 16.
Cards had nine digit rows plus three zone rows, twelve total; usually
only 0 and 1-9 were printed. "Bury me face down, 9 edge first."

- David.Thompson1 at worldnet.att.net
Oct 23 '06 #41
Dave Thompson said:
On Wed, 11 Oct 2006 06:14:35 +0000, Richard Heathfield
<in*****@invalid.invalidwrote:
>EBCDIC's okay with the ordering, but the alphabets are non-contiguous,
coming as they do in rows of ten on boundaries of sixteen.

s/ten/nine and eight (averaging 8.6overbar)/
Yes, I was relying on my (obviously faulty) memory. Later, I had occasion to
look the table up, and noted that the alphabet was in nines rather than
tens, but by then I didn't recall having claimed otherwise. :-)
But you do rhyme with 'seas of green', FWIW.
Cue the solo on something brassy (tuba?).

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 23 '06 #42
Dave Thompson <da*************@worldnet.att.netwrote:
>
Cards had nine digit rows plus three zone rows, twelve total; usually
Ten digit rows -- 0 can be either a zone or a digit, depending on the
particular usage.

-Larry Jones

I won't eat any cereal that doesn't turn the milk purple. -- Calvin
Oct 23 '06 #43

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

Similar topics

4
by: fix | last post by:
Hello, i need to protect my xsl file. In my xsl i have a mechanism for defining a personal stylesheet, what i want to do is, if it possible, find a mechanism for Obfuscated the xsl source code ....
1
by: Wibo | last post by:
Hello, we have a large application, that gave weird behavior. On W2K we're suffering from instable program ececution from time to time, untill now we managed to workaround these problems. On...
1
by: assaf | last post by:
hi all i am using PreEmptive Solutions dotfuscator (community edition). and i am getting 'TypeLoadException' for a simple interface that i defined. how can i debug an obfuscated application? ...
0
by: Steve Covert | last post by:
Has anyone encountered problems with building an installer for a Windows app using Wise? In my case, the installation fails due an obfuscated dll. Instructions are provided for remedying this from...
58
by: Jeff_Relf | last post by:
Hi Tom, You showed: << private const string PHONE_LIST = "495.1000__424.1111___(206)564-5555_1.800.325.3333"; static void Main( string args ) { foreach (string phoneNumber in Regex.Split...
5
by: Thomas Garai | last post by:
Hi, Does anybody know the details of the obfuscated C contest that was around a couple of years ago? I have a couple of pearlers I would like to enter.... hehehe :) cheers
0
by: daechulsohn | last post by:
Just thought I would contribute some knowledge for a change. After hours tracking down a problem with obfuscated code, where we were getting the exception : System.TypeLoadException: Method a...
4
by: Paul E Collins | last post by:
For those who appreciate such things, here's a bit of obfuscated C# I knocked up in a spare moment at work. http://CL4.org/comp/jabberwocky.txt P. -- www.CL4.org
35
by: +-={K-SoL}=-+ | last post by:
when I try to reference 2 obfuscated libraries at the same time visual studio gives me a compilation error since the obfuscator has converted some name spaces to a and b in both libraries, now I...
4
by: Bry | last post by:
I'm trying Obfuscation for the first time using the community edition of dotfuscator that ships with vs .net 2005. After building my code, I load the compiled .exe into dotfuscator and let it...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.