c - Aliasing with char *, unsigned char * and signed char * -
a char *
(and qualified variants) may alias anything. signed char *
, unsigned char *
(and qualified variants) exempt this?
in other words, i've learned it's idea apply restrict
char*
function arguments if don't expect them alias pointer parameters of other types (because alias them):
int func(struct foo *f, char * restrict s /*different object*/);
can drop restrict
keyword signed , unsigned char variants so?
int sfunc(struct foo *f, signed char *s /*different object*/); int ufunc(struct foo *f, unsigned char *s /*different object*/);
also may pointers signed , unsigned variant of same type alias each other? in other words if expect pointer int , pointer unsigned , should point different objects, should int *
, unsigned *
parameters each restrict
-qualified?
/* , u should different */ int uifunc(int * /*restrict?*/ i, unsigned * /*restrict?*/ u);
the rule (c11 6.5/7):
an object shall have stored value accessed lvalue expression has 1 of following types:
- a type compatible effective type of object,
- a qualified version of type compatible effective type of object,
- a type signed or unsigned type corresponding effective type of object,
- a type signed or unsigned type corresponding qualified version of effective type of object,
- an aggregate or union type includes 1 of aforementioned types among members (including, recursively, member of subaggregate or contained union), or
- a character type.
char
, signed char
, unsigned char
character types (ref: 6.2.5/15). earlier bullets answer question signed , unsigned types.
bear in mind fixed width types typedefs may refer various other types, take care there.
Comments
Post a Comment