This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Structure Size

Hi....I am writing code for STR710FZ2 using Keil compiler.when i checked the sizeof a structure which i defined i got the size as 12 eventhough the actual size is 10.Since arm is 32 bit i can only defines structure whose size is a multiply of 4...can anybody tell me a way to overcome this problem....

Parents
  • i got the size as 12 eventhough the actual size is 10

    You're basing your expectations on incorrect assumptions. The actual size of that struct is exactly what the compiler says it is.

    can anybody tell me a way to overcome this problem....

    By understanding that the problem is not what you think it is. The problem is not that the compiler isn't giving you the struct size and alignment you expect. The problem is that you're trying to use a C struct for something it's not meant to be used for. While extensions like __packed may appear to solve the issue, they really just muddy the water some more.

    C structs are for use inside your program, not for interfacing with the outside world. If you have to match externally defined data formats, use different methods. E..g write single bytes suitably isolated from C internal variables.

Reply
  • i got the size as 12 eventhough the actual size is 10

    You're basing your expectations on incorrect assumptions. The actual size of that struct is exactly what the compiler says it is.

    can anybody tell me a way to overcome this problem....

    By understanding that the problem is not what you think it is. The problem is not that the compiler isn't giving you the struct size and alignment you expect. The problem is that you're trying to use a C struct for something it's not meant to be used for. While extensions like __packed may appear to solve the issue, they really just muddy the water some more.

    C structs are for use inside your program, not for interfacing with the outside world. If you have to match externally defined data formats, use different methods. E..g write single bytes suitably isolated from C internal variables.

Children
No data