Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Type-Safe C

Name: Anonymous 2017-04-27 11:37

>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.

Name: Anonymous 2017-04-28 12:10


int main(){
printf("%s", 05);
return 0;
}

Name: Anonymous 2017-04-29 16:05

>>2
Not an argument.

Name: Anonymous 2017-04-29 16:08

>>3
it would crash your program though

Name: Anonymous 2017-04-29 21:53

>>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: Anonymous 2017-04-29 22:08

>>5
The program should do what I tell it to do without imposing some arbitrary legality on operations.

Name: Anonymous 2017-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: Anonymous 2017-05-01 6:02

>>7
Type safe means you don't need an MMU for protection.

Name: Anonymous 2017-05-04 14:07

>>5
That's an octal number

Name: Anonymous 2017-05-04 15:36

>>2
Any compiler would warn about it.

Name: Anonymous 2017-05-04 22:47

>>8
Protection from what?

Name: Anonymous 2017-05-04 23:02

>>11
Invalid operations

Name: Anonymous 2017-05-05 3:12

>>12
And who's to say whether an operation is valid or not? Maybe my program is SUPPOSED to overwrite other processes' address spaces.

Name: Anonymous 2017-05-05 3:21

>>13
the OS and MMU

Name: Anonymous 2017-05-21 10:20

gcc has transparent_union which allow to refer to union members
as the name of unions -> free type-safe code.

Name: Anonymous 2017-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: Anonymous 2017-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;}

Name: Cudder !cXCudderUE 2017-05-22 7:43

type freedom > type safety

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List