[Spice-devel] [PATCH spice-protocol] vd_agent: Do not define structures without fields
Uri Lublin
uril at redhat.com
Thu May 31 15:42:16 UTC 2018
On 05/31/2018 05:58 PM, Frediano Ziglio wrote:
>>
>> According to C standard the size of a structure without fields is
>> not defined (see
>> https://stackoverflow.com/questions/21851930/size-of-empty-structure-in-c-and-c).
>> As use almost use GCC we used these structures having 0-size. This is
>
> As we almost only use GCC ...
.. currently these structures are of size 0.
This can become a problem ... if 2 sides ...
>
>> usually not a problem however can became a problem if 2 side talking
>
> side -> sides
>
>> a given protocol uses these structures.
>
> uses -> use
>
>> To avoid such possible mismatch (for instance having one side C and the
>> other C++ which define these structure as having 1 as size) add an
>
> define -> defines, structure -> structures
>
>> empty (0-size array) field.
>> Although a 0-size array is not considered also that portable we use
>> extensively this feature with different compiler never encountering
>
> compiler -> compilers
>
>> issues.
>>
>> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
Ack.
I tested it with a following simple program, f.c,
(building it with gcc and g++):
---
#include <stdio.h>
#include <spice/vd_agent.h>
int main()
{
printf("sizeof(VDAgentClipboardRelease)=%lu\n",
sizeof(VDAgentClipboardRelease));
return 0;
}
---
Uri.
>
> I should have checked before sending.
>
>> ---
>> spice/vd_agent.h | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/spice/vd_agent.h b/spice/vd_agent.h
>> index 7109ede..dda7044 100644
>> --- a/spice/vd_agent.h
>> +++ b/spice/vd_agent.h
>> @@ -234,6 +234,7 @@ typedef struct SPICE_ATTR_PACKED VDAgentClipboardRelease
>> {
>> uint8_t selection;
>> uint8_t __reserved[sizeof(uint32_t) - 1 * sizeof(uint8_t)];
>> #endif
>> + uint8_t dummy_empty_field[0]; /* C/C++ compatibility */
>> } VDAgentClipboardRelease;
>>
>> typedef struct SPICE_ATTR_PACKED VDAgentMaxClipboard {
>
> Frediano
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
>
More information about the Spice-devel
mailing list