msvc struct initialisation query
-
imagine a struct declared as follows:-
typedef struct
{
int integerArray[];
} testStruct;I can instantiate like this:-
testStruct a = {
{1,2,3}
};Which is all well and good. But, if the struct declaration is changed to an int* member:-
typedef struct
{
int *integerArray;
} testStruct;How can I now instantiate it so that integerArray points to my array of {1,2,3} ?? in gcc, you can cast {1,2,3} to (int *), as follows:-
testStruct a = {
(int *){1,2,3}
};But msvc doesn't allow that. Is there another way to make this instantiation? thanks Jon
using System.Beer;
-
imagine a struct declared as follows:-
typedef struct
{
int integerArray[];
} testStruct;I can instantiate like this:-
testStruct a = {
{1,2,3}
};Which is all well and good. But, if the struct declaration is changed to an int* member:-
typedef struct
{
int *integerArray;
} testStruct;How can I now instantiate it so that integerArray points to my array of {1,2,3} ?? in gcc, you can cast {1,2,3} to (int *), as follows:-
testStruct a = {
(int *){1,2,3}
};But msvc doesn't allow that. Is there another way to make this instantiation? thanks Jon
using System.Beer;
Jon Hulatt wrote:
Is there another way to make this instantiation?
How about:
testStruct a = { new int(1), new int(2), new int(3) };
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
-
Jon Hulatt wrote:
Is there another way to make this instantiation?
How about:
testStruct a = { new int(1), new int(2), new int(3) };
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
Very clever, anyway I suspect he wants the allocation to happen onto the stack. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]