10-11-2011, 03:09 PM
Hi, I need some advice regarding typedef and boolean types; we use the following typedefs in a common 'types' header file (I have only included the relevant ones here):
typedef unsigned int uint16_t;
typedef unsigned int bool_t;
#define FALSE ((bool_t)0U)
#define TRUE ((bool_t)1U)
If we create a structure containing a bit-field, for example..
typedef struct
{ // Structure used to pass software/hardware info to the system
i8pc_string_t i8pc_software_version; // Software version number
i8pc_string_t i8pc_serial_number; // Serial number
bool_t bl_hardware_supported:1; // Hardware revision is supported
} st_software_info_t;
and then modify the boolean member as such...
sts_sw_info.bl_hardware_supported = FALSE;
then this is ok, however when we test the value as such...
if (sts_sw_info.bl_hardware_supported == FALSE)
{
// Do something...
}
then we violate rule #10.1. Is this due to the underlying type expected by the if statement?
In addition, if any bit-field is defined using a typdef'd type (e.g. uint16_t u4_my_bits:4;), then we violate rule 6.4; why is this since uint16_t has been typedef'd as unsigned int?
Any help appreciated,
Regards
Richard
typedef unsigned int uint16_t;
typedef unsigned int bool_t;
#define FALSE ((bool_t)0U)
#define TRUE ((bool_t)1U)
If we create a structure containing a bit-field, for example..
typedef struct
{ // Structure used to pass software/hardware info to the system
i8pc_string_t i8pc_software_version; // Software version number
i8pc_string_t i8pc_serial_number; // Serial number
bool_t bl_hardware_supported:1; // Hardware revision is supported
} st_software_info_t;
and then modify the boolean member as such...
sts_sw_info.bl_hardware_supported = FALSE;
then this is ok, however when we test the value as such...
if (sts_sw_info.bl_hardware_supported == FALSE)
{
// Do something...
}
then we violate rule #10.1. Is this due to the underlying type expected by the if statement?
In addition, if any bit-field is defined using a typdef'd type (e.g. uint16_t u4_my_bits:4;), then we violate rule 6.4; why is this since uint16_t has been typedef'd as unsigned int?
Any help appreciated,
Regards
Richard
<t></t>