Buffer size allocation
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
Walter Roberson
2011-9-26
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 个评论
Alexandre De Barros
2012-4-10
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 个评论
Guy Rigot
2011-9-27
1 个评论
Walter Roberson
2011-9-27
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Troubleshoot Compilation Errors 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!