This is basically dynamic memory allocation with typecasting.
Literal meaning: dynamically allocating memory to _V3Signals, a size of an array of char, being typecasted to a pointer to pointer to _v3signal.
This size is the sizeof a pointer to pointer to _pscsignal times that of (max_v3_signal+PSC_NOMPINS).
Break it down into parts:
1) newchar[] allocates an array of characters.
2) The number of characters allocated is determined by taking the size of a pointer to a pointer sizeof (_pscsignal **) and multiplying it by (_max_v3_signals + PSC_NOMPINS)
3) The resulting array is cast to a pointer to a pointer to a _v3signal.
4) Which is then stored in _V3Signals.
Nah, I was thinking something totally different because I didn't recognize the typecasting so I thought the person who wrote it was trying to use c-style memory allocation
I would expect (in C++) something more along the lines of:
_v3Signals = new _v3signal*[_max_v3signals+PSC_NOMPINS] ;, although I can't be sure if that is entirely right. The _pcsignal** in the original code code concerns me.
The _pcsignal** in the original code code concerns me.
It is the standard method to declare array of pointers to something in C using malloc.
Next lines would probably initialize it.
Looks like somebody couldn't get rid of C habits.
Actually I would expect to use sizeof(_pscsignal *), not sizeof(_pscsignal **)
because new x will return *x, not x nor **x, and _V3Signals have type of _v3signal**. You should create array of pointers to _v3signal (new _v3signal*[10]), like cire shown you
Sorry for disturbing.Just to verify one last thing.
Is the code above mean
I got a double pointer _V3Signals in type v3signal.
So now assign dynamic memory to the double pointer that will point to array of 10space which are in type v3signal and will store only pointer value?
Please correct me if i am wrong. thanks u very much.
I know both also assign dynamic memory.But what is the diff ?
The same as with type** x = new type*[n]; and x[i] = new type.
First line creates an array of uninitializated (invalid) pointers.
Second line takes one such pinter from array and makes it point to newly created object.