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

Pages: 1-4041-

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-01 13:59

Neither.

Name: Anonymous 2011-08-01 14:03

In YOuRe AnUs ;-)

Name: Anonymous 2011-08-01 14:03

I don't use obsolete languages.

Name: Anonymous 2011-08-01 14:09

>>3

your pointer fells good man.

Name: Anonymous 2011-08-01 15:21

e) var p *int

Name: Anonymous 2011-08-01 15:23

f) whatever ``in Lisp'' does.

Name: Anonymous 2011-08-01 15:24

g) p : int ref
h) p :: Ref Int
i) (: p (Boxof Integer))
j) Cudder.

Name: Cairnarvon !WokonZwxw2 2011-08-01 15:30

They're all pointers to the same entity. What kind of programmer are you.

Name: Anonymous 2011-08-01 15:35

>>2-9
Fuck you.

My choice:
int* p

Name: Anonymous 2011-08-01 16:02

<- Yo bitch, check my dubz!!

Name: Anonymous 2011-08-01 16:22

>>3,5,9,11
Oh my /prog/... What happened to you?

Name: Anonymous 2011-08-01 17:56

>>12
My dof's ded ;_;

Name: Anonymous 2011-08-01 18:57

a)

because p is the pointer, not int.

Name: Anonymous 2011-08-01 19:16

a)

because *p is an expression of type int.

Name: Anonymous 2011-08-01 19:20

b)
Because p is a variable of type (int*).

Name: Anonymous 2011-08-01 19:32

a)
what >>15 said

Name: Anonymous 2011-08-01 20:16

Use b in a typedef and then use that typedef to declare the necessary variables.

Name: Anonymous 2011-08-01 20:22

a)
Probably because I'm straight.

Name: Anonymous 2011-08-01 20:37

>>18
And call the new type Pint.  I feel like some beer right now.

Name: Anonymous 2011-08-01 22:05

i put the p in [spoiler]\prog[/spoiler]

Name: Anonymous 2011-08-01 23:10

#include <stdio.h>

int main(int argc, const char *argv[]) {
    int n = 42;
    int *p = &n;
    printf("n = %d\n", n);
    printf("*p = %d\n", *p);
    if (n == *p) {
        printf("n = *p\n");
        printf("Therefore n and *p are both of type 'int'.\n");
        printf("Therefore we declare them:\n");
        printf("int n;\n");
        printf("and\n");
        printf("int *p;\n");
    }  
    return 0;
}

Name: Anonymous 2011-08-01 23:22

The C syntax is pretty retarded.

You would think it should be int* p. Because you are declaring a pointer to an int. And a pointer to an int can be considered a type. For ex. typedef pint = int* (or something like that, i forget).

But then you also have int *p, *q, *r. Suddenly the * is separated from the int. THIS IS WRONG.

Name: Anonymous 2011-08-02 0:01

OP here. Thanks for all of your responses. I love how pointless this subject is, and yet every programmer I've meet is usually pretty particular about this, and they have reasons to justify their convention.

I do

int * p;

because it looks like I'm trying to multiply a variable with a type, and it doesn't make any sense, and I like to confuse people whenever possible. And it is also very nice and spaced out. If the asterisk is right next to either word, it all looks too scrunched up for me, and it gives me a headache.

Name: Anonymous 2011-08-02 0:05


typedef void* pointer;
...
...
pointer x = NULL;


I only use void pointers.

Name: Anonymous 2011-08-02 0:07

>>25
Interesting... I could do high-level functions that look nice using this. Thanks for the idea.

Name: Anonymous 2011-08-02 0:10

>>25

what about when you dereference them? The casts would look ugly...unless you encapsulated them with functions.

Name: Anonymous 2011-08-02 0:14

>>25
Now you have declare the type every time you dereference your pointers.

PIG DISGUSTING

Name: Anonymous 2011-08-02 0:38

I do
int *p;
which makes it easier to do
int& *p;

Name: Anonymous 2011-08-02 0:48

1 Name: Anonymous : 2011-08-01 13:57

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

    e) here

FTFY

Also, 'e' here.

Name: Anonymous 2011-08-02 3:11

>>29
Get OuT SePPLeS sTraIGHt MaN

Name: Anonymous 2011-08-02 6:34

If you're programming in C, put the * to right like so:

int *p;

If you're programming in C++, put the * to left like so:

int* p;


If you do anything else, you're doing it wrong.

In C, you tend to think about things more in terms of what it is pointing to. int *p is a pointer to an integer, not so much an integer-pointer.

The reason it makes sense to put the * to left in C++ is largely due to pragmatics, is because the * is a part of type. "p" is an integer-pointer, it's not so much a pointer to an integer.

Furthermore, when you factor in const and volatile qualifiers, placing * to the left becomes more important for nested pointers and references.

int* volatile* const* p;

You now read p's type from right to left. A pointer to a constant pointer to a volatile pointer to an integer.

In C, which traditionally didn't have const, and volatile had slightly different rules, this didn't make so much sense.

Name: Anonymous 2011-08-02 7:12

>>32
So in C++, you want int* a, *b, *c;?

Name: Anonymous 2011-08-02 7:18

>>32
There is no difference in how pointers are defined in C or C++. For both int * is of different type than char *, for example.

C's declarations are designed to mirror the usage and C++ doesn't change anything about that. It's reference system even supports this:
int *&p; //p is a reference to a pointer
The reason that C++ doesn't use &int is for compliance with the C standard. There is no reason to suddenly change your mind about this.

It also helps by pairing up the qualifiers with the right asterisks:
int *volatile *const *p; //equal to int (*volatile (*const (*p)));

Name: Anonymous 2011-08-02 8:24

>>33
No: int* a,* b,* c;

Name: Anonymous 2011-08-02 9:45

int *p; // "I am allocating an int, and declaring a pointer to it called p."

Name: Anonymous 2011-08-02 9:53

>>36
No you are not allocating anything.
Also, get out and bring your SEPPLES comments mark and your straight men quotes with you.

Name: 36 2011-08-02 9:54

>>37
fuck you faggot, I use // all the time in my C code; it's infinitely more convenient that /**/

Name: Anonymous 2011-08-02 10:11

>>35
That's stupid and you're stupid.

Name: Anonymous 2011-08-02 10:15

>>38
Only when writing one-line comments, whose use is considered BAD PRACTICE!!

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

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