>C lacks type safety. typedef struct struct_x{int typesafe_data; } name; How this isn't type safe? Also, it stores the struct within the same size as int.
>>4 Yeah but you're lying to the program by telling it 05 is a legal memory address in the program's address space. A program shouldn't be expected to behave correctly when given nonsensical input.
Name:
Anonymous2017-04-29 22:08
>>5 The program should do what I tell it to do without imposing some arbitrary legality on operations.
Name:
Anonymous2017-04-30 18:23
>>6 The ``arbitrary legality" is imposed not by the program, but by the OS and MMU. The program is doing exactly what you tell it to do - read memory at address 5. But since that is classified as an invalid operation by the memory management system, your program gets sent a kill signal.
Name:
Anonymous2017-05-01 6:02
>>7 Type safe means you don't need an MMU for protection.
gcc has transparent_union which allow to refer to union members as the name of unions -> free type-safe code.
Name:
Anonymous2017-05-21 10:27
typedef union blah{ int typesafe_content;} typesafe_int __attribute__ ((__transparent_union__)); typesafe_int a(typesafe_int z){ z=(typesafe_int)100;return z;} //below won't work int main(){return a((typesafe_int)1);}
Name:
Anonymous2017-05-21 10:31
typedef union blah{ int typesafe_content;} typesafe_int __attribute__ ((__transparent_union__)); typesafe_int a(typesafe_int z){ z=(typesafe_int)100;return z;} //below works int main(){return a((typesafe_int)1).typesafe_content;}