Reputation: 4739
I think that *something
and * something
are different.
What does the additional white space do?
occurs here -> void * malloc( size_t number_bytes );
Upvotes: 4
Views: 1779
Reputation: 123448
The *
operator in a declaration always binds to the declarator; the line
void * malloc (size_t number_bytes);
is parsed as though it had been written
void (*malloc(size_t number_bytes));
It's an accident of C syntax that you can write T *p;
or T* p;
or even
T * p;
but all of them are parsed as T (*p);
-- the whitespace makes no difference in how the declarations are interpreted.
Upvotes: 2
Reputation: 838096
When you use an asterisk to get the value of an address it is called the dereference operator. For example:
int x = *something;
In the example in your question the asterisk has a different meaning because it is part of a type, not part of an expression. It is used to specify that the return type is a pointer (in your specific example, a void pointer).
The extra space does not mean anything and is ignored by the compiler. It is there only to aid readability.
Upvotes: 10
Reputation: 9866
int* foo == int *foo == int * foo == int * foo
The whitespace does not make any difference to the compiler.
Upvotes: 13
Reputation: 50943
In your void * malloc(...)
example, void *
is the type. malloc
returns a pointer to void, which is just a pointer that needs to be cast to a particular type in order to be useful.
Upvotes: 0
Reputation: 29722
Check out this article on Pointers
Those two lines do the exact same thing.
Upvotes: 0
Reputation: 134167
C ignores extraneous whitespace, so "* "
should have the same effect as "*"
.
If you want more clarification, please post a code example.
Upvotes: 1