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-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!!

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