1
Ideas / Re: Require explicit (un)initialization.
« on: January 30, 2019, 09:06:15 PM »
I don't like mandatory initialization either, but implicit initialization to the zero value of the type is confusing too. The compiler should just issue an error, not a warning when it detects that a variable is used before intialization. There are border cases where it is difficult, or plain impossible to determine if a variable was initialized or not, requiring explicit initialization in these cases is OK IMHO. This is basically what I get with `-Wall -Werror`.
Regarding a possible syntax to specify uninitialized status, I would suggest:
This could be used to tell the compiler that a variable is no longer valid and thus prevent its use in further computations. For example:
Regarding a possible syntax to specify uninitialized status, I would suggest:
Code: [Select]
int a = void; // a not initialized, warning if used before later assignment.
This could be used to tell the compiler that a variable is no longer valid and thus prevent its use in further computations. For example:
Code: [Select]
free(p);
p = void;
return p; // error: use of an invalid value.