Do I have a gcc optimization bug or a C code problem?

前端 未结 9 2377
借酒劲吻你
借酒劲吻你 2021-02-06 00:57

Test the following code:

#include 
#include 
main()
{
    const char *yytext=\"0\";
    const float f=(float)atof(yytext);
    siz         


        
9条回答
  •  Happy的楠姐
    2021-02-06 01:38

    In the C99 standard, this is covered by the following rule in 6.5-7:

    An object shall have its stored value accessed only by an lvalue expression that has one of the following types:73)

    • a type compatible with the effective type of the object,

    • a qualified version of a type compatible with the effective type of the object,

    • a type that is the signed or unsigned type corresponding to the effective type of the object,

    • a type that is the signed or unsigned type corresponding to a qualified version of the effective type of the object,

    • an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union), or

    • a character type.

    The last item is why casting first to a (char*) works.

提交回复
热议问题