Ecere SDK/eC Forums
https://ecere.org/community/
Print view

some boolean data type errors
https://ecere.org/community/viewtopic.php?f=1&t=400
Page 1 of 1
Author:  jonaspm [ Wed Mar 25, 2015 12:32 am ]
Post subject:  some boolean data type errors

Hello Jerome, redj and all the community!

Today i got some trouble, because i wrote this:

Code: Select all

class Form1 : Window
{
   /*WINDOW properties stuff...*/
   bool neg1=false;
   bool neg2=false;
then I have this:

Code: Select all

      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         String negacion;
         String negacion2;
         if( this.neg1 == false){
            negacion = PrintString("");
         }else{
            negacion = PrintString("¬");}
         if( this.neg2 == false){
            negacion2 = PrintString("");
         }else{
            negacion2 = PrintString("¬");}
and the compiler jumps with some errors:

Code: Select all

Default Compiler
Building project Logica using the Debug configuration...
Compiling...
form1.ec
   form1.ec:16:13: error: syntax error
   form1.ec:16:13: error: syntax error
   form1.ec:17:13: error: syntax error
   form1.ec:17:13: error: syntax error
   form1.ec:16:14: error: couldn't find member false in class Form1
   form1.ec:161:4: error: couldn't determine type of this.false
   form1.ec:161:4: error: couldn't determine type of this.false
   form1.ec:161:4: error: couldn't determine type of this.false=
   form1.ec:161:4: error: couldn't determine type of this.false=

Logica.exe (Debug) - 9 errors, no warning   
lines 16 and 17 are:

Code: Select all

   bool neg1=false;
   bool neg2=false; 
Also, line 161 appears to not be the problem... (the compiler is unable to find the exact spot where the problem is, though I think it's related to the ifs above).


Thanks in advance! :)
Author:  jerome [ Wed Mar 25, 2015 8:26 am ]
Post subject:  Re: some boolean data type errors

Hi Jonas,

At the moment it is not possible to initialize default values for properties together with their declaration within a class. However, you can do it separately, e.g.:

Code: Select all

class Form1 : Window
{
   /*WINDOW properties stuff...*/
   bool neg1, neg2;
   neg1 = false, neg2 = false;
Additionally, it is not necessary to initialize these values to 'false' as they would automatically be zeroed by default (and the value of 'false' is 0).

Another option would be to write a constructor:

Code: Select all

class Form1 : Window
{
   bool neg1, neg2;
   Form1()
   {
      neg1 = false;
      neg2 = false;
   }
}
Best regards,

Jerome
All times are UTC-05:00 Page 1 of 1