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

How to understand this line of c ?

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

Dec 31 '05
56 2774
Keith Thompson writes:
I knew that only because I happened to read your response immediately
after Kenneth's article. Please read <http://cfaj.freeshell.org/google/>
and follow its advice *before* you post here again; it's important.
Thanks for the pointer!
If you're talking about something like interpreting the string pointed
to by argv[i] as an integer, such as the string "123", that's not
typecasting (or, more properly, casting).


I neglected to mention that I might cast one of the members of the
array.
If it's not casting, what is it? Converting?

--
Red Cent

Jan 4 '06 #51
"Red Cent" <tr**********@sbcglobal.net> writes:
Keith Thompson writes:

[snip]
If you're talking about something like interpreting the string pointed
to by argv[i] as an integer, such as the string "123", that's not
typecasting (or, more properly, casting).


I neglected to mention that I might cast one of the members of the
array.
If it's not casting, what is it? Converting?


Casting refers to an explicit cast operator, such as (type)expr.
Converting refers to a conversion from one type to another; this is
the operation performed by the cast operator.

If you're talking about converting one of the members of the argv
array (i.e., a pointer) to an integer type, that doesn't make much
sense. If you're talking about translating a string value to an
integer value, such as "123" --> 123, that's not what "conversion"
usually means.

Can you provide an example, in C code, of what you're talking about?

--
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.
Jan 4 '06 #52
Keith Thompson writes:
Can you provide an example, in C code, of what you're talking about?


(in reference to casting a string to an int)

Off the top of my head, I can't remember when I've used this. Vaguely
I remember having a program that needed to run X number of times. So I
passed an argument "123" which main's argv got.

Now in order to run it that many times, I needed to cast "123" to an
int 123, so I could use it in a counting loop.

If I get a chance, I'll look through some of my source code to see
where I've used it.

Jan 4 '06 #53
tr**********@sbcglobal.net wrote:

Not so much treat argv as an int, but typecast it to another
variable if needed (as a number)

I have no idea how this came up, due to the total lack of context
(see my sig below for proper reply technique using the broken
google usenet interface).

At any rate, why would you wish to cast it to anything else, when
it is known to be a pointer to a pointer to a char? You can't
change that fact.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Jan 4 '06 #54
"Red Cent" <tr**********@sbcglobal.net> writes:
Keith Thompson writes:
Can you provide an example, in C code, of what you're talking about?


(in reference to casting a string to an int)

Off the top of my head, I can't remember when I've used this. Vaguely
I remember having a program that needed to run X number of times. So I
passed an argument "123" which main's argv got.

Now in order to run it that many times, I needed to cast "123" to an
int 123, so I could use it in a counting loop.


Ok, there's where the confusion is coming from.

A cast is a very specific thing; it's a C operator that specifies a
conversion from one type to another. It's possible to convert a
pointer to an integer, but it's seldom useful. For example, if your
program's first argument happens to be the string "123", casting
argv[1] to int: (int)argv[1], will give you an integer representation
of the address at which the string "123" is stored in memory.

What you're doing can be called a conversion, but it's not really a
conversion in the sense usually used in C. You probably do something
like passing the value of argv[1] (or argv[i]) to the atoi() or
strtol() function.

--
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.
Jan 5 '06 #55
At about the time of 1/3/2006 3:48 AM, pemo stated the following:
"Daniel Rudy" <sp******@spamthis.net> wrote in message
news:aH****************@newssvr25.news.prodigy.net ...
At about the time of 12/31/2005 11:27 AM, pemo stated the following:
"lnzju" <ge*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googl egroups.com...
main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}
Here it is a little clearer [hopefully?]

#include <stdio.h>

// x will be 1 (the name of this app would be in argv[0]) if we
// don't invoke the app with some args.
//
main(x)
{
char c;

// zero then!
//
--x;

while(c = "J!Mpwf!Zpv\1"[x])
{
// No need for the -1 if we add 1 to the literal's characters...
//
// "I Love You\1"
//
c = c - 1;

x++;

putchar(c);
}
}


You know, the code that the OP provided is the reason why I hate
wannabe's trying to be hack programmers to impress the rest of us.
Anyone who codes like that needs to be shot, not once, not twice, but
thrice. Perferably in the groin.

wannabes - who, me, them, you?


Who ever wrote that code. Granted, I'm fairly new to C myself, so I
could be considered a wannabe...But you will not catch me coding like that.
--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
Jan 5 '06 #56

"Daniel Rudy" <sp******@spamthis.net> wrote in message
news:Nm*******************@newssvr13.news.prodigy. com...
At about the time of 1/3/2006 3:48 AM, pemo stated the following:
"Daniel Rudy" <sp******@spamthis.net> wrote in message
news:aH****************@newssvr25.news.prodigy.net ...
At about the time of 12/31/2005 11:27 AM, pemo stated the following:

"lnzju" <ge*******@gmail.com> wrote in message
news:11**********************@g43g2000cwa.goog legroups.com...
>main(_){for(--_;putchar(_++["J!Mpwf!Zpv\1"]-1););}
Here it is a little clearer [hopefully?]

#include <stdio.h>

// x will be 1 (the name of this app would be in argv[0]) if we
// don't invoke the app with some args.
//
main(x)
{
char c;

// zero then!
//
--x;

while(c = "J!Mpwf!Zpv\1"[x])
{
// No need for the -1 if we add 1 to the literal's characters...
//
// "I Love You\1"
//
c = c - 1;

x++;

putchar(c);
}
}

You know, the code that the OP provided is the reason why I hate
wannabe's trying to be hack programmers to impress the rest of us.
Anyone who codes like that needs to be shot, not once, not twice, but
thrice. Perferably in the groin.

wannabes - who, me, them, you?


Who ever wrote that code. Granted, I'm fairly new to C myself, so I
could be considered a wannabe...But you will not catch me coding like
that.


I don't think it was meant to be taken seriously, i.e., it's a bit of
obfuscated fun, and possibly started off life somewhere under
http://www.ioccc.org/
Jan 5 '06 #57

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

Similar topics

10
by: Simon Mansfield | last post by:
I have been given a list of exercises to do by my tutor, one of which is this: http://www.cems.uwe.ac.uk/~amclymer/Software%20Design%20and%20C++/Exercises/Exercise%208/Exercise.html Which i am...
3
by: orekinbck | last post by:
Hi There I'm probably missing something fundamental here but I don't understand the code in the OnThreadException routine, which is found in MSDN under the topic: Application.ThreadException...
8
by: Charles | last post by:
I do not understand why I am getting a "Specified cast is not valid" error, since it has worked before. Something has changed and I am not really sure what it could be. I am looking for something...
6
by: Yan | last post by:
Here is the code: class A {}; void (A::*A) (); // Line 3 int main() { A a; // Line 6 return 0; }
24
by: sonnystarks | last post by:
Created: http://www.websitesamples.j-starks.com/bio/ and attempted XHTML Transitional validation. Came up with 13 errors that do not make sense. Please do same and tell me what it is asking for,...
54
by: smnoff | last post by:
Below is a section from string.c at this linkhttp://cvs.opensolaris.org/source/xref/on/usr/src/common/util/string.cthat I am trying to fully understand.I don't fully understand LINE 514; not to...
2
by: Sean Hammond | last post by:
Anyone understand this? Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02) on linux2 Type "help", "copyright", "credits" or "license" for more information. .... """Send 'input' (string) to the...
2
by: hellt | last post by:
HI all, i found winreg module from http://www.rutherfurd.net/python/winreg/index.html very useful and simple, instead _winreg. But i have a problem with this module, in its iterable part. look...
4
by: hirsh.dan | last post by:
i have a functions that writes information to a file. inside that function i have a line in which i call another function. if this line is executed, nothing is written to the file, but if i remark...
5
by: Thierry | last post by:
Hello fellow pythonists, I'm a relatively new python developer, and I try to adjust my understanding about "how things works" to python, but I have hit a block, that I cannot understand. I...
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.