Initialization of string in REXLANG
-
I got this warning in the Compiler Window but everything is working fine :
"Warning compiling file 'WasteSrcfile.c' (line 30): variable 'stringTemp' is used without initialization"
The initialization was one like this :
char stringTemp[80];
Something like this, to initialize an empty string will not work :
char stringTemp[80] = "";
-
@scoobsalamander
Hi, you can divide the initialization into two commands:char stringTemp[80]; stringTemp = "";
if you want to be sure that the array is empty. The warning will disappear.
Cheers,
Jan -
@reitinge I did try this before but then I can't even compile due to an error.
But apparently it was because I did the initialization of this string inside the main routine.
Bizarre that it is throwing a warning for the string 'stringTemp' and not for the long variable 'index'.
Both are only used inside the main routine.This is the complete code which is now running without a warning :
//assigning inputs to variables, these variables are READ-ONLY double input(0) inputGLAS; double input(1) inputGFT; double input(2) inputPMD; double input(3) inputRA; double input(4) inputTEXT; double input(5) inputP_K; //assigning variables to outputs, these variables are WRITE-ONLY string output(0) stringOUT; //value to send to y0 output char stringTemp[80]; //the init procedure is executed once when the REXLANG function block initializes long init(void) { return 0; } //the main procedure is executed repeatedly (once in each sampling period) long main(void) { long index = 0; //char stringTemp[80]; stringTemp=""; strcat(stringTemp,"Vergeet+niet+volgend+vuilnis+buiten+te+zetten+:+"); if (inputGLAS!=0) { strcat(stringTemp,"Glas"); index=index+1; } if (inputGFT!=0) { if (index!=0) { strcat(stringTemp,",+"); } strcat(stringTemp,"GFT"); index=index+1; } if (inputPMD!=0) { if (index!=0) { strcat(stringTemp,",+"); } strcat(stringTemp,"PMD"); index=index+1; } if (inputRA!=0) { if (index!=0) { strcat(stringTemp,",+"); } strcat(stringTemp,"Restafval"); index=index+1; } if (inputTEXT!=0) { if (index!=0) { strcat(stringTemp,",+"); } strcat(stringTemp,"Textiel"); index=index+1; } if (inputP_K!=0) { if (index!=0) { strcat(stringTemp,",+"); } strcat(stringTemp,"Papier+en+Karton"); } stringOUT=stringTemp; return 0; } //the exit procedure is executed once when the task is correctly terminated // (system shutdown, downloading new control algorithm, etc.) long exit(void) { /* PUT YOUR CODE HERE */ return 0; }
-
This post is deleted!