开发者

Overlaying a struct onto a u_char pointer

My professor has instructed me that we can lay a struct over (casting) the pointer in memory we are getting in order to more easily interpret the data. I asked about this in class today and this is what he said would work.

This is not compiling complaining about how it can't cast it. What am I doing wrong? I am about to resort to parsing the data manually...

struct DataStruct
{
    u_char DEST_ADDRESS[6];
    u开发者_StackOverflow社区_char SOURCE_ADDRESS[6];
};

struct DataStruct* testData;
testData = (struct DataStruct*)pkt_data;


You can't have an statement outside of a function.

Change:

struct DataStruct* testData;               // definition okay outside function
testData = (struct DataStruct*)pkt_data;   // statement not okay outside function

to:

struct DataStruct* testData = (struct DataStruct*)pkt_data;  // definition with
                                                             // initializer okay
                                                             // outside function
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜