I am trying to make c++ pass an array into a function by referencing the first element of the arrays address.
Screenshot is where I am currently at. Highlighted in red is the current errors.
NOTE: the code is from a book (i think).
>>59582748
First year CS student? I literally have to do the same thing in Pascal (not sure how)
>>59582770
I am not doing this for school.
I am doing this for learning + maybe it will help with future school assignments.
Think that should just beconst float *gdude.
No[&0]there.
http://pastebin.com/2WbZXqUS
heres a pastebin
>>59582788
But the way arrays work with the compiler is that the compiler is just taking the address of the first element of g.
So why can't I write g[&0]?>
>>59582748
Last error: 18. That's what's up. You're using an rvalue.
>>59582799
it has to do with rvalues and shit
The g pointer is already pointing towards the first element. Just use that
>>59582799
&g[0] is the address of the first element, I think.
You can't specify the size of an array in a function signature. Numbers in arrays in function signatures make no sense.
>>59582807
But I want to pass the address of the first element of g. I dont know what an r or L value is , but I'm going to ask is there any way to pass the address as an lvalue?
>>59582828
I don't want to use that.
This isn't for a program I have to write, work, school, or anything else.
I just want to pass the g pointer that is pointing towards the first element without writing const float* g.
>>59582836
>is there any way to pass the address as an lvalue?
This dude gave you the right answer. It's an lvalue. Lvalues are values that are left of the = sign.
>>59582788
An * can be used as an lvalue can't they? So here's a pointer to a pointer called g.
>>59582799
this is trying to specify you want to access the element &0 in the array g[]. Unless &0 somehow coerces to an int, yer hooped.
The meaning ofint * g
*g is an int (dereferencing g gives int)
g is an int* (g points to an int)
>>59582850
well it works if you do
>>59582858
I meant i want to pass g[0]'s address without writing g.
Since all thats happening is that const float * g is grabbing the address of g[0] then i should be able to wrote g[&0]
>>59582799
>g[&0]
Because 0 is a constant and doesn't have an address. Just write g[] or *g
>>59583013
g[&0] is not anything. Arrays need an index that is a positive integer.
'&0' is semantically "the address of zero" it doesn't make sense.
If you really wanted the address of the first element in g, you'd use &g[0] but that doesn't work in a function header.
>>59583013
I don't know. You're asking questions about design decisions in C++. I have no idea why you can't just say 'g[&0]'. I also have no idea why lvalues are required when clearly 'g[&0]' means 'g'. I would just accept the facts and move on. All the nitty-gritty details may come later.
>>59583051
>>59583043
Yes. It would be &g[0].