Buffer size allocation
3 views (last 30 days)
Show older comments
When declaring an array of type USINT32 (typedef'd to unsigned long): USINT32 buffer[512] and passing the array as a function argument, the size of that buffer, according to polyspace, is dependent on the size of a char (as defined in the target settings). In the target settings, a long is defined as 32 bits. This would indicate the above buffer would contain 512*4=2048 bytes. This is however only the case when the size of a char is set to 8 bits. If setting the size of a char to 16 bit in the target settings, polyspace will indicate the size of the buffer to be 1024 bytes, even though the size setting of char should not have influence on the size of the buffer. Could you clarify this behaviour for me?
Another issue I run into is that when checking the result settings from within polyspace, the target settings are not displayed correctly. They will show the current settings from the project manager, and not the settings as used in the verification. Neither is the correct name of the generic target displayed (it always displays mcpu). Thank you!
0 Comments
Answers (3)
Walter Roberson
on 26 Sep 2011
C has no specific "byte" data type. A "byte" in C is the size of char, and the size of everything else is measured in units of the size of char. 1024 16-bit bytes is the same amount of storage as 2048 8-bit bytes.
In computers, "byte" is not defined as 8 bits: it is instead approximately "the smallest naturally-addressable storage unit". "Naturally addressable" here is distinguished from the possibility that the computer might have special instructions able to access smaller units (such as bits or nibbles).
In the late 1970's to early 1980's, it looked for a time as if 9-bit bytes were going to become predominant, as DEC and Honeywell had some fairly advanced systems that used 9 bit bytes.
0 Comments
Alexandre De Barros
on 10 Apr 2012
Hi!
There is indeed a problem in the tooltip with the size in bytes of pointers when the size of char is 16 bits.
In the example above, the size should be 2 bytes, not 4.
There is an EBR (External Bug Report) on our website:
0 Comments
Guy Rigot
on 27 Sep 2011
1 Comment
Walter Roberson
on 27 Sep 2011
You are right, in that context if "byte" meant character units, then in the second case it should say "points to 2 bytes".
Sorry, I don't have any further ideas; we have had very few polyspace questions come through so I do not have any product-specific background knowledge to go on.
See Also
Categories
Find more on Troubleshoot Compilation Errors in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!