Author Topic: TRUE <> true  (Read 2540 times)

jcfuller

  • Sr. Member
  • ****
  • Posts: 394
    • View Profile
TRUE <> true
« on: February 02, 2020, 11:58:05 AM »
I know this has been discussed somewhere before but I'm not sure of the outcome or the  bcx, bc9 differences.

BOOL <> bool
TRUE <> true
FALSE <> false

upper case is Windows
lower case is c++

both are valid in different situations
The translator will always translate to upper case

I decided to use _bool _true _false for the c++ versions in bc9

#define _bool bool
#define _true   true
#define _false false

Any discussion?

James



MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1899
    • View Profile
Re: TRUE <> true
« Reply #1 on: February 02, 2020, 01:58:34 PM »
With all the mods that went into BCX after I initially stepped away, I'm surprised this is even an issue.

My first thought was, if $CPP is specified then the global flag Use_Cpp could be used to emit true, false, and bool.

Indeed, that very idea is present in the code that handles the COPYFILE command ( and it seems to function correctly )

Code: [Select]
  IF UseCpp THEN
        Stk$[++Ndx] = ",false);"
      ELSE
        Stk$[++Ndx] = ",FALSE);"
      END IF

Before I would commit to making that kind of change across the entire landscape of BCX, I'd want to get some more input.
I code in C, not Cpp, so it's never been an issue for me.  And I'm not the guy to ask what unintended consequences that
globally changing TRUE FALSE BOOL to true false bool would have when $CPP is specified.

Baby steps ...

jcfuller

  • Sr. Member
  • ****
  • Posts: 394
    • View Profile
Re: TRUE <> true
« Reply #2 on: February 02, 2020, 02:07:53 PM »
I tried the $CPP route and as far as I remember it did not work. You need both. Upper case for Windows lower for c++, that is why I went with what I did. I guess :)
I too want more input

James
 

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1899
    • View Profile
Re: TRUE <> true
« Reply #3 on: February 02, 2020, 02:32:16 PM »
I would be less apprehensive about adding your #defines for _bool, _false, and _true to the standard emission (when $CPP is used).

On the other hand, you could simply add those to your BCX.INI file, if you didn't want to think about it too hard.  :-)

Robert

  • Hero Member
  • *****
  • Posts: 1145
    • View Profile
Re: TRUE <> true
« Reply #4 on: February 02, 2020, 03:02:27 PM »
I know this has been discussed somewhere before but I'm not sure of the outcome or the  bcx, bc9 differences.

BOOL <> bool
TRUE <> true
FALSE <> false

upper case is Windows
lower case is c++

both are valid in different situations
The translator will always translate to upper case

I decided to use _bool _true _false for the c++ versions in bc9

#define _bool bool
#define _true   true
#define _false false

Any discussion?

James

_Bool (with bool as an alias) is now part of C (as of C99).

From Pelle's C Help File

Code: [Select]

<stdbool.h> [C99]
 
#include the standard file <stdbool.h> to define a readable form of the boolean keyword.

The file contains four macros which are expanded as follows:

Macro                                Expanded to
bool                                       _Bool
true                                        1
false                                       0
__bool_true_false_are_defined 1


MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1899
    • View Profile
Re: TRUE <> true
« Reply #5 on: February 03, 2020, 08:26:25 PM »

_Bool (with bool as an alias) is now part of C (as of C99).

From Pelle's C Help File

Code: [Select]

<stdbool.h> [C99]
 
#include the standard file <stdbool.h> to define a readable form of the boolean keyword.

The file contains four macros which are expanded as follows:

Macro                                Expanded to
bool                                       _Bool
true                                        1
false                                       0
__bool_true_false_are_defined 1


Here's what I now understand.  I don't know what ( if anything ) that should be changed in BCX.

BCX normally converts "true", "false", and "bool" to UCASE to work with Windows

TRUE = true = 1

FALSE = false = 0

BOOL (the datatype) is not the same as _Bool (the datatype)

DIM bull AS BOOL : bull = 3 : PRINT bull    ' RESULT = 3

DIM bull AS _Bool : bull = 3 : PRINT bull    ' RESULT = 1

Code: [Select]

#include <windows.h>
#include <stdio.h>
#include <stdbool.h>

int main(int argc, char *argv[])

{

  bool bull = 3;  // a bool will only hold 0 or 1, regardless of assignment (LccWin32 complains of overflow)

  printf("% d\n", bull);    // prints 1     using Mingw, Pelles, and LccWin32

  printf("% d\n", true);  // prints 1                      ditto

  printf("% d\n", false);  // prints 0                     ditto

  return 0;

}


Robert

  • Hero Member
  • *****
  • Posts: 1145
    • View Profile
Re: TRUE <> true
« Reply #6 on: February 03, 2020, 11:22:23 PM »
Even more complexity detailed here


http://forums.codeguru.com/showthread.php?332831-Visual-C-General-What-is-the-difference-between-BOOL-and-bool


Particularly, the last question and answer

Q: Is it OK if I test the return of a Windows SDK function against 'TRUE'?

A: Actually no, it is not OK.

Have a look at the link for details.

I think James' solution in the original post is probably the best. I would like to hear opinions on whether it would be a good idea to implement it in BCX. Yes, like the other posters on this topic, I too am looking for input.

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 1899
    • View Profile
Re: TRUE <> true
« Reply #7 on: February 04, 2020, 08:03:06 AM »
_Bool is COOL. 

_Bool is unambiguous.  I want easy access to _Bool


My proposal:

(1) add <stdbool.h> to the list of #includes that BCX emits

(2) make _Bool a BCX keyword ( i.e., BCX will change things like _BOOL to _Bool  and _boOL to _Bool, etc )

(3) Change BCX to NOT modify the word "bool" in any way - if you type "boOL", BCX emits "boOL"

(4) Change BCX to ALWAYS emit "true" and "false" in lower case.

From the standpoint of values, in the context below, TRUE = true and FALSE = false unconditionally.

Code: [Select]

#include <windows.h>
#include <stdio.h>
#include <stdbool.h>

int main(int argc, char *argv[])
{
printf("TRUE  = % d\n",TRUE);
printf("true  = % d\n",true);
printf("FALSE = % d\n",FALSE);
printf("false = % d\n",false);
return 0;
}