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

where do you put the * in type declarations?

Name: Anonymous 2011-08-01 13:57

a) int *p;
b) int* p;
c) int * p;
d) int*p;

c) here

Name: Anonymous 2011-08-02 10:18

>>39
There exist opinions that differ from yours.

>>35
Terrible!

Name: Anonymous 2011-08-02 11:51

Real programmers don't need pointers for anything.

Name: Anonymous 2011-08-02 14:03


    int* p;
//   ^--------That's pointer to int faggots

Name: Anonymous 2011-08-02 14:51

    int *p;
//      ^--------(*p) is of type int


    int *const p[];
//      (    ^   )----Read this like a statement.
//   ^----------------The returned value is of type int.[/code]
If you index p as an array you get a value, which if dereferenced as a constant pointer will return an int.


This is how it is implemented. If we wanted to group the pointer and array declaration with the type, there would be a much more natural way:
(const* int)[] p; //p is an array of constant pointers to int

But someone decided that we do it the other way and we have  for the last 30 years. Writing int* p only leads to confusion because it really means int(* p).

Name: Anonymous 2011-08-02 14:52

>>44
    int *const p[];
//      (    ^   )----Read this like a statement.
//   ^----------------The returned value is of type int.

Name: Anonymous 2011-08-02 17:26

I never use pointers directly.

typedef int * intptr

Name: Anonymous 2011-08-03 13:11

e) const int * const p

Name: Anonymous 2013-07-21 3:07

int p[];

Name: Anonymous 2013-07-21 3:10

Look, ma, I'm replying to 2 year old threads!

That said, >>46-san really needs to read Section 5 of https://www.kernel.org/doc/Documentation/CodingStyle .

Name: Anonymous 2013-07-21 3:20

I think this was the first thread I created on /prog/. No it's the second.

Name: Anonymous 2013-07-21 3:24

>>1
I'm smart, so I just typedef int* ip
saves a few kbs of keystrokes.

Name: Anonymous 2013-07-21 3:53

>>51
I'm smarter than you, so I use #define typedef t.  It saved me 3.1 Gigabytes of disk space.

Name: Anonymous 2013-07-21 8:40

>>52
Wow! It really works, I was amazed at how easily the gigabytes just disappeared.

Name: Anonymous 2013-07-21 9:08

Use void.h or stay pleb.

Name: Anonymous 2013-07-21 9:56


10 DIM A%, B
20 A%=VARPTR(B)

Name: Anonymous 2013-07-21 12:51

I use int* a; when doing single declarations, and int *a, *b; or int *const a; when doing multiple declarations or pointers with qualifiers.

Name: Anonymous 2013-07-21 12:59

Also, type declaration semantics in C are completely retarded. If it were up to me, they would be interpreted right-to-left, simple and straightforward. Like so:
int volatile *const [] * (int, int) * a; // 'a' is a pointer to a function(int, int) returning a pointer to an array of const pointers to volatile int

Name: Anonymous 2013-07-21 13:26

I mean seriously, what the fuck is this shit?
volatile int *const(*(*a)(int, int))[]
They should put that in the newspaper next to the crosswords and sudokus. "Decipher the type declaration".
Just why, I ask.

Name: Anonymous 2013-07-21 13:30

>>58
lelelele i no know le cdecl cuz im be retard /g/ro!!!!!! le e/g/in!!!!! xd xd xd xd xddddddddddddddddddddddddddddddddddddddd

Name: Anonymous 2013-07-21 13:55

To me, b) makes the most sense.

You are declaring a variable called 'p', which has a type of 'integer pointer'.

Name: Anonymous 2013-07-21 14:05

i just typedef all of my variables as void * and then cast them if I need to

no reason to have c being all statically typed

Name: Anonymous 2013-07-22 2:21

>>16
This one.

P.S. Jews

Name: Anonymous 2013-07-22 4:08

int is a type.
float is a type.
double is a type.
int* is NOT a type.

For example:
int a, b; // declares two ints
float c, d; // declares two floats
double e, f; // declares two doubles
int* g, h; // DOESN'T declare two pointers to ints, but a pointer to an int and an int


The compiler applies * to the variable, not the type. Therefore, you should associate * with the variable, not the type, just as you would when you're dereferencing the pointer (*p) or incrementing it (p++) or decrementing it (p--).

Surely, you wouldn't write expressions like the int x =* p; or int y =++ x;. int* p is just as retarded.

Therefore, int *p is the only correct answer.

Name: Anonymous 2013-07-22 4:10

Check my power of two.

Name: Anonymous 2013-07-22 4:54

check 'em

Name: Anonymous 2013-07-22 5:01

>>64
nice 26 :3

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