Bug 35928 - type qualifiers ignored on function return type
Summary: type qualifiers ignored on function return type
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.2.4
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-14 02:35 UTC by littlestar
Modified: 2008-04-14 04:10 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.6
Known to fail: 4.2.2 4.2.3 4.2.4
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description littlestar 2008-04-14 02:35:55 UTC
the following code generate a warning on gcc 4.2.4

warning: type qualifiers ignored on function return type

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct testabc{int class;}* THANDLE;

const THANDLE test()
{
        THANDLE x;

        x = (THANDLE)2;

        return x;
}

int main(int argc, char **argv)
{
     const THANDLE p = test();
     return (int)p;
}
Comment 1 Andrew Pinski 2008-04-14 03:33:02 UTC
The const in "const THANDLE" applies to the pointer type and not the element the pointer is pointing to.  So the warning is correct.
Comment 2 littlestar 2008-04-14 03:49:13 UTC
but how to applies to the pointer type and the element
the pointer is pointing to.

I don't want someone modify my pointer and the pointing to?

but the following code has no warning, why?

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct testabc {int Class;}THANDLE;

const THANDLE* test()
{
        THANDLE *x;

        x = (THANDLE*)2;

        return x;
}

int main(int argc, char **argv)
{
     const THANDLE *p=  test();
        return (int)p;
}

Comment 3 Andrew Pinski 2008-04-14 04:10:57 UTC
"const THANDLE" in the first case is equivalant to "THANDLE* const" when THANDLE a struct.

> but how to applies to the pointer type and the element
> the pointer is pointing to.

With the typedefs, you can't.