How to understand this line of c ?

K

Keith Thompson

Malcolm said:
It's not associative

a = INT_MAX;
b = 1;
c = -1;

(a + b) + c;
and
a + (b + c);

won't necessarily be the same.

Ok, but we were talking about commutativity, not associatativy.
 
P

pemo

Daniel Rudy said:
At about the time of 12/31/2005 11:27 AM, pemo stated the following:
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?
 
R

Red Cent

pemo said:
At about the time of 12/31/2005 11:27 AM, pemo stated the following:
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?
What is that --_ in the for initializer?
 
R

Red Cent

Keith said:
Red Cent said:
pemo said:
At about the time of 12/31/2005 11:27 AM, pemo stated the following:



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


What is that --_ in the for initializer?


_ is an identifier. -- is the predecrement operator.

Duh.... That's what I get for posting before looking at the entire
thread! Question already answered. But thank you!

Faux Pas #2002 using usenet... READ THE ENTIRE THREAD :)
 
X

Xiaocao Feidao

_ can be the name of a variable. Yes, _ is a legal varible name for C.
Thanks to tmp123!
 
T

truthgrepper

My usual problem with using argv is I forget it's an array of strings.
I either forget to cast to an int if I need it or forget to use **argv
(pointers to pointers)
 
K

Kenneth Brody

My usual problem with using argv is I forget it's an array of strings.
I either forget to cast to an int if I need it or forget to use **argv
(pointers to pointers)

(See the numerous other posts about properly quote using Google Groups.)

Why in the world would you treat argv as an int?

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:[email protected]>
 
T

truthgrepper

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

Keith Thompson

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

This was in response to:

Kenneth Brody said:
(See the numerous other posts about properly quote using Google Groups.)

Why in the world would you treat argv as an int?

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.

argv is of type char**. I can't think of any circumstances in which
it would make sense to cast it to int (i.e., (int)argv). Can you show
us an example of what you're talking about?

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

Red Cent

Keith said:
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 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?
 
K

Keith Thompson

Red Cent said:
Keith Thompson writes: [snip]
If you're talking about something like interpreting the string pointed
to by argv 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?
 
C

Chuck F.

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

Red Cent

Keith said:
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.
 
K

Keith Thompson

Red Cent said:
(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) to the atoi() or
strtol() function.
 
D

Daniel Rudy

At about the time of 1/3/2006 3:48 AM, pemo stated the following:
At about the time of 12/31/2005 11:27 AM, pemo stated the following:
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
 
P

pemo

Daniel Rudy said:
At about the time of 1/3/2006 3:48 AM, pemo stated the following:
At about the time of 12/31/2005 11:27 AM, pemo stated the following:



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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top