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

int* p vs. int *p

Name: Anonymous 2009-10-29 0:18

What do you think about the difference between the following declarations? Which do you prefer?

int* p;
int *p;

It's often said the first is C++ style and the second is C style. I prefer C but conceptually the first declaration makes a lot more sense to me. You're defining a variable p of type int*. p is an int*. You dereference it, *p, when you want the int. Makes sense. The second example to me seems like gobbledygook, but it's the way the C authors thought of it, because of this bullshit:

int *p, *q;

So what the fuck is the deal? Can someone who uses "int *p" syntax explain to me what goes through your head when you write that garbage?

Name: Anonymous 2009-10-29 20:49

Name: Anonymous 2009-10-29 22:25

OP here again, for the "int *p" crowd, how do you deal with const and restrict? Would you write "int *restrict p"? This looks fucking stupid to me. I write "int* restrict p", which makes sense.

Name: Anonymous 2009-10-29 22:57

int *whatever is the only one that makes sense because it's declared the same as when you dereference it.
this thread is stupid

Name: Anonymous 2009-10-30 0:25

>>82
Yes, that is exactly how I write that. I guess if you understand the "you read type declarations from right to left" thing and still think int *p is ugly, there's no more discussion we can have. To me, int *p is intuitive from how I read type definitions. To you, not. That's that.

Name: Anonymous 2009-10-30 1:50

>>84
No, this is bullshit. Why is the positive of the space intuitive? You can't even explain it.

Name: Anonymous 2009-10-30 1:51

s/positive/position/

Name: Anonymous 2009-10-30 1:51

>>82
I use Sepples, so I don't use const/restrict with respect to the variable declarations. I might use a const int *, but never an int const *. There's just no need to make such a distinction anymore.

Name: Anonymous 2009-10-30 1:54

OK guys, let's just admit that Java had things right on this syntax issue.

   int[] dicks;

makes sense.

   int dicks[];

does not.

Name: Anonymous 2009-10-30 1:55

Hello dinosaurs.  Its hard to believe, but modern languages actually don't use * anymore.  * makes things more complicated, when you can make the computer do it for you (Python, Java, C#).  Also, * takes time to run, and when you use a language that doesn't use *, that means your program runs faster.

Name: Anonymous 2009-10-30 2:39

>>89 is right. Think of all those multiplications that you're making the processor do.

Name: Anonymous 2009-10-30 2:47

>>89
I lol'd

Name: Anonymous 2009-10-30 2:55

>>64

You are so unbelievable thick.


int *p, *q, *r, i, j, k;


Very easy to see which ones are pointer and which just ints. Absolutely no way you're going to confuse them.

int* p, q, r;
int i, j, j;


Gotta look twice for that *.

Just give up.

Name: Anonymous 2009-10-30 4:23

>>89
I'm sorry, but next time you have to take a more subtle approach to trolling. I can't rate you higher than 3/10.

Name: Anonymous 2009-10-30 5:47

>>92
int* p;
int* q;
int* r;
int i;
int j;
int k;


Enjoy you're shitty code and unclean diffs when having more than one declaration per line.

Name: Anonymous 2009-10-30 5:50

>>88

Finally something different and correct.

Name: Anonymous 2009-10-30 6:19

>>94

Enjoy your scrolling.

Name: Anonymous 2009-10-30 7:52

int main() {
  int *p = 0;
  p();
}


C QUALITY

Name: Anonymous 2009-10-30 7:53

>>97
int main() {
()
Reported.  Now anyone can call you're main with as many arguments as they like!  THE HORROR!!!

Name: Anonymous 2009-10-30 9:05

>>98

RUN FOR YOUR LIVES

Name: Anonymous 2009-10-30 9:23

>>92
No, I am not thick. You are arguing for the position of the asterisk *purely because of the grammar* of variable declarations; not what they semantically mean.

Name: Anonymous 2009-10-30 9:27

I also want to say, stop being a dick. We've said over and over that you *shouldn't* use multiple declarations in C++ style, and you keep bringing it back up as an example of why the style is bad.

Name: Anonymous 2009-10-30 9:31

C > Sepples.
∴ C style declarations > Sepples style declarations.
</thread>
now get out. all of you.
this thread is just the same handful of posts being repeated over and over and over.

Name: Anonymous 2009-10-30 9:41

>>100

What the fuck does that mean?

int* i, j;
for (i = 0, j = 5; i < j; ++i);


int *i, *j;
for (i = 0, j = 5; i < j; ++i);


Which one is easier to read? Though so.

Name: Anonymous 2009-10-30 9:48

I find C++ style easier to understand conceptually, but I only use C style when coding C.

Name: Anonymous 2009-10-30 9:56

In D, int * is the type, so int *a, b; means b is also a pointer.
(Which also means it should be written as int*)
Really it's how C should have been to begin with.

Name: Anonymous 2009-10-30 10:04

int a, *b, **c, ***d; is how it should be.
the asterisks ARE NOT part of the type. what fucking moron came up with that idea?
each asterisk represents a layer of indirection, not a goddamn data type. they are not part of the type and should not be thought of as such.
also:
int *a; //declare
*a; //dereference

in this way you declare them the same as how you get the value that it points to.

Name: Anonymous 2009-10-30 10:09

>>106

Thank you

Name: Anonymous 2009-10-30 10:09

>>98
Here's something that may surprise you: main() can take more than two arguments.
int main(int argc, char **argv, char **envp)

Name: Anonymous 2009-10-30 10:29

>>108
EXPERT C PROGRAMMER

Name: Anonymous 2009-10-30 10:31

>>108
Can it take 42 (XD) arguments?

Name: Anonymous 2009-10-30 11:03

>>98
Reported.  Now anyone can call you're main with as many arguments as they like!  THE HORROR!!!
Now anyone can call you're main
you're main

I AM NOT MAIN

Name: Anonymous 2009-10-30 11:07

>>111
does not know the age old /prog/ tradition of switching your and you're.

Name: Anonymous 2009-10-30 11:16

>>112 YHBT

Name: Anonymous 2009-10-30 11:25

>>111
Your the main dog now man.

Name: Anonymous 2009-10-30 12:07

>>110
At least with glibc and a dynamically linked file, the next arg after envp is dynamic linker information.
/* contents of 'ld' array from int main(int argc, char **argv, char **envp, char **ld) */
ld[0] = "ELF"
ld[1] = "/lib/libc.so.6"
ld[2] = ""
ld[3] = ""
ld[4] = ""
ld[5] = ""

If the program was statically linked, this ld parameter will be NULL.

(Of course, this is treading well into implementation-defined territory, so YMMV.)

Name: Anonymous 2009-10-30 12:38

STATICALLY LINK MY ANUS

Name: Anonymous 2009-10-30 12:45

>>115 here. I was playing with the "next" arg after that, it's quite weird. Seems to be a pointer to pointer to pointer to nothing:
#include <stdio.h>
int main(int argc, char **argv, char **envp, char **ld, void ***what) {
    printf("%p\n", **what);
    return 0;
}

This produces (nil); statically linked, what itself is (nil).

Name: Anonymous 2009-10-30 13:13

hax my loader

Name: Anonymous 2009-10-30 13:28

>>108
OK /prog/, poll time. When was the last time you actually passed an environment to main? How about in a non-toy program? exactly

Name: Anonymous 2009-10-30 13:31

>>119
Every day?

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