Char* x vs char *x

Which side are you on?

Attached: english pointer.jpg (930x698, 86K)

the second one you fucking disgusting poo in loo degenerate

boost::string

I use a modern programming language so I don't have to deal with pointers.

I prefer the idea of char* x.
BUT syntactically, you have char *x, *y
so really char *x is the correct approach in C

Pshhh std::string suckas

>i'm sheltered, so I don't have to deal with the realities of life

char* x is superior because you show what type the variable is. It just makes more sense. “This is a char pointer to x” vs “this is a char. Actually just kidding it’s a pointer to a char.”
I mean come on.

what kind of math is this? char times x

>declaring multiple variables on a single line
absolutely disgusting

I don't like it either.
But hey, that's the syntax.

Always MyType* x;

This is the operation of creating a variable x the type of which is a pointer to a MyType object, NOT creating a MyType object that happens to be a pointer

char = 1 Byte
char* = machine size pointer to char
*x = dereferencing the pointer x
null terminated strings are an abonimable cancer

C is masochistic anyway

Stop mf my sides is pahurting

Just don't fucking do it

>char* x is superior because you show what type the variable is. It just makes more sense. “This is a char pointer to x” vs “this is a char. Actually just kidding it’s a pointer to a char.”
>I mean come on

char x = the expression x evaluates to a char
char *x = the expression *x evaluates to a char

This is objectively the correct approach when using C or C++.

>char *x = the expression *x evaluates to a char

Never thought about it this way, wish I did when I was a tutor, would have saved some headaches

Attached: download.jpg (239x211, 9K)

> char* x vs char *x
char * x

Compromises are for fags

>char* x
That's stupid, if you declare more than one variable, you have to declare as char *x, *y[\code]. Clearly the * is associated with the variable name, not with the variable type.
>char *x
That's stupid, if you're going to declare a char pointer return, you're going to declare as char*[\code], not char *[\code]. Clearly the * is associated with the type.

There's no satisfactory answer, this notation was poorly designed.

Fucking tags, let's try it again.

>char* x
That's stupid, if you declare more than one variable, you have to declare as char *x, *y. Clearly the * is associated with the variable name, not with the variable type.
>char *x
That's stupid, if you're going to declare a char pointer return, you're going to declare as char*, not char *. Clearly the * is associated with the type.

There's no satisfactory answer, this notation was poorly designed.

Hard mode:
char ptr[4];
uint32_t w = -1;

((uint32_t *) ptr)[0] = w;
or
memcpy(ptr, &w, sizeof w);

None, as both have undefined behavior

char x = 'x';
char* c = &x;
char y = c[0];
long address = #c;

why reuse punctuation when you could just use more of it

>both have undefined behavior
>crypto libraries use both
Pick one. How exactly is memcpy UB, according to you?

The second is not.

union {
char c[4];
uint32_t u;
} val = { .u = w };

_Static_assert(sizeof(uint32_t) == 4, "uint32_t must be 4 bytes");

use the same code on a big endian and low endian machine, you will get different results.

Not memcpy per se, just the way you used it.
uint32_t is guaranteed to have at least 32 bits, but can have more. Doing memcpy(ptr, &w, sizeof w) is undefined behavior because if uint32_t has more than 32 bits it will overwrite unallocated memory

I like
const char * const

>uint32_t is guaranteed to have at least 32 bits, but can have more
No uint32_t is guaranteed to be exactly 32 bits, with no extra padding bits. Don't confuse it with unsigned long for uint_least32_t.
It's not guaranteed to exist, though.

auto, you C luddites.

My bad, then

Get to

char*
speaks to the type, a pointer to a char

*x is retarded. It's the name of the variable and is the same expression as dereferencing.

I've stopped using C the moment I graduated and its been....7 years now since. Java, C#, Ruby, C++, Python since then (not in that particular order).

Point is I've forgotten a lot of C since. Feels like I'm missing out.

>speaks to the type, a pointer to a char
This breaks down when you're talking about arrays and pointers to functions.
>It's the name of the variable and is the same expression as dereferencing.
That's literally the intention: "Declaration is the same as usage".

Wait, I'm being stupid:
union {
char c[sizeof(uint32_t)];
uint32_t u;
} val = { .u = w };

neither side
char * x

Attached: yuuko_hibike_grin.jpg (249x329, 13K)

100% best way

"Worst-of-both-worlds" solution.

Is the first? Why?
>unions
Are UB (you're supposed to only access the last written member).
The implication being that ptr[0] will be different depending on byte order? But suppose you only care about the 32-bit word as a header of sorts, and don't wish to access it by byte: then it doesn't matter, because the 32 bit word will be the same.

Pic related is what libsodium does, you're definitely correct then.

Attached: Screenshot_2018-10-08_18-54-30.png (396x192, 22K)

char * x

>Is the first? Why?
Breaks the strict aliasing rules.
>Are UB (you're supposed to only access the last written member).
This is only true in C89. Type-punning with unions is explicitly allowed in C11 and is the proper way to do it.

if you're using the same word on the same machine, its totally fine. If you save it to a file then try to load it on a different machine it will be different. Its really sad honestly.

What's the type of y in
char* x, y

I'm cd code user

>>char x = the expression x evaluates to a char
>char *x = the expression *x evaluates to a char
Interesting way to see it

Attached: 1440168180847.jpg (500x500, 30K)

Garbage.

>Breaks the strict aliasing rules.
But it works on my machine, and regardless of optimization level.

char* x is better for teaching
I remember being confused being taught char *x since it's similar to dereferencing

Behold the sloc master.

pls explain difference

Attached: e1eac1bf8e70924155f4fb35615a00dedcf4b379884d955c142f118e37dbdc9c.jpg (900x900, 83K)

please go back to javascript

The correct side

I'm on the right (left) side

Dubs confirm

std::any

I know that char *x is usually the standard, but I think char* x makes more sense.
It looks more like declaring a new pointer while char *x makes it look like you're dereferencing the pointer.

typedef * pointer

char pointer a;

>char*
niggerlicious

>boost
this is a white man's bored pajeet

>BUT syntactically, you have char *x, *y
BUT multiple declaration is bad practice to begin with.

char *ptr; obviously.

What, do you also write void(* ptr)(); ?

Agree. The asterisk is part of the type, so it makes sense to put it next to the type.

My man.

char * for variable / member declarations
char* for everything else
or, if C++ use
template
using ptr = T*;
...
ptr string;

char *c, *d;
otherwise you would get
char* c, *d;
which is ugly obviously

btw how do you pronouce char?
as in character or charcoal?

I pronounce it as "charcoal", but english is not my first language so there's that.

This guy gets it.

Do you also wear a scarf and glasses without lenses?

Why do people with awful ideas rush to be the first reply?

Look like a design flaw to me.

char* c, d

should declare two character pointers called c and d.