Recommend to use `$` as a modifier for temporary variables of Vala in CCode
Now Vala uses _
as the only modifier of variables signed by Vala. However, variable names may still conflict with whis, such as the use of xxx_length
or _tmpxxx_
.
But $
is a legal part of variable names in C since C89, while it's illegal to be in the variable name in Vala. So collisions can never happen if the variable names signed by Vala contains $
. It may be possible to modify each variables signed by vala with one $
for safety.
For example:
void main () {
string[] tab = {"Hello", ",", " ", "world", "!"};
var tab_length1 = tab.length;
}
/tmp/1.vala.OLU9W1.c: In function '_vala_main':
/tmp/1.vala.OLU9W1.c:28:14: error: redeclaration of 'tab_length1' with no linkage
28 | gint tab_length1 = 0;
| ^~~~~~~~~~~
/tmp/1.vala.OLU9W1.c:26:14: note: previous declaration of 'tab_length1' with type 'gint' {aka 'int'}
26 | gint tab_length1;
| ^~~~~~~~~~~
error: cc exited with status 256
Or:
void main () {
string[] tab = {"Hello", ",", " ", "world", "!"};
var _tmp0_ = 1234;
}
/tmp/1.vala.TWNYW1.c: In function '_vala_main':
/tmp/1.vala.TWNYW1.c:28:14: error: conflicting types for '_tmp0_'; have 'gint' {aka 'int'}
28 | gint _tmp0_ = 0;
| ^~~~~~
/tmp/1.vala.TWNYW1.c:20:16: note: previous declaration of '_tmp0_' with type 'gchar *' {aka 'char *'}
20 | gchar* _tmp0_;
| ^~~~~~
error: cc exited with status 256
Although these examples are on purpose, maybe someone will still use these names?$
can perfectly solve this problem and why not try it on...
Edited by Zhou Qiankang