I get these warnings:
type_d.h:13: warning: initialization from incompatible pointer type
type_d.h:13: warning: excess elements in scalar initializer
type_d.h:13: warning: (near initialization for ‘p0’)
type_d.h:13: warning: excess elements in scalar initializer
type_d.h:13: warning: (near initialization for ‘p0’)
type_d.h:13: warning: excess elements in scalar initializer
type_d.h:13: warning: (near initialization for ‘p0’)
but if I alter the syntax to
const char* p0[] = { "## ", "## ", " ", " " };
the warnings are all gone. what's exactly the difference between using * [] and ** ? I really thought they were just the same, just like * and [] or ** and [][].
If I did it like p0[][] = { ... would it be different at all?
Name:
Anonymous2007-11-14 12:48
* is just a pointer to some data
[] explicitly tells the compiler that you have a pointer to an array of items
>>1
Just read the declarations. When you declare "const char** p0" you are saying "pointer to a pointer to a const char". Declaring "const char* p0[]" you are saying "array of pointers to const chars".
From my POV: C pointers are NOT related to arrays in any way. The confusion only arises from the (very specific) fact that pointers can be "indexed" like arrays. Other than this, they have nothing to do with each other. Have this in mind when using sizeof -- notice how it behaves differently when used with pointers and arrays.
Exception made for [] arrays as formal parameters since those will act like pointers as far as I know. Also, cocks.
Name:
Anonymous2007-11-18 12:02
>>21
TL;DR: with **, the compiler expects a single initializer of type "pointer to pointer to const char", and with *[] the compiler expects a compound initializer made up of "pointers to const char" because arrays != pointers
Name:
Anonymous2007-11-18 12:32
The confusion only arises from the (very specific) fact that pointers can be "indexed" like arrays.
And the reverse: &array[0] == array (== &array), and array[x] == *(array+x).
C pointers and arrays are very much related. They just differ in their declaration/initialization, and sizeof (and maybe something else, I don't remember right now).
Name:
Anonymous2007-11-18 13:26
>>23 And the reverse: &array[0] == array (== &array), and array[x] == *(array+x).
incorrect, `&array[0]' equals `array' only in value context.
Also, neither `&array[0]' or `array' equal `&array'.
As for array[x] == *(array+x) correct, however certain compilers seem to like *(array+x) more than array[x].
C pointers and arrays are very much related. They just differ in their declaration/initialization, and sizeof (and maybe something else, I don't remember right now).
read that FUQIN thread i linked to you fucking moron >>8
>>28 What do you mean by 'value context'?
That these two expressions are equal only in value.
Proof?
learn C moron.
If type is 'type' then &type is 'type *'
type != type *
And?
Just felt like sharing a bit of my huge knowledge. (i am huge therefore my knowledge must be HUGE)
Your mind will blast when you understand why *(array+x) /might/ compile to better code than array[x].
A hint: check how most compilers read the source code.
I am disgusted by the amount of C morons here in /prog/, mainly because C is trivial.
>>30 What other contexts are there for those expressions?
haha, oh wow.
Answer me first these:
The c char sequence 'A'
is it an expression?
If it is, what is it's type?
It's signedness?
It's size?
They still point to the same memory location.
you are now thinking with your assembler.
And no -- they don't have to be equal in value.
Explain
I will simply give some hints: consider how the compiler reads what is given to him, notice that x is an expression that has to be evaluated, understand how the compiler evaluates code, how the compiler generates assembly, and be englightened.
Answer me first these:
It's an expression (in my view: anything that can appear on the right-hand side of an assignment operator). I don't want to argue definitions though, I'd prefer you just answer my question.
And no -- they don't have to be equal in value.
Gimme a link or something.
I will simply give some hints:
I still don't understand, and am not willing to spend a lot of time thinking about this, so just tell me what you're getting at.
>>33
An expression, simply to put, is anything that can be evaluated to a value.
Gimme a link or something.
Your C book.
I still don't understand, and am not willing to spend a lot of time thinking about this, so just tell me what you're getting at.
I don't care.
Lastly, to answer about the expresion 'A'
type: int
signedness: signed (okay saying signedness here is not correct, i should've asked whether it's a signed or unsigned type)
size: sizeof (int), equal or more than 1.