C++: TDM-GCC: error with bool

Discuss other programming languages besides AutoHotkey
User avatar
jeeswg
Posts: 5555
Joined: 19 Dec 2016, 01:58
Location: UK

C++: TDM-GCC: error with bool

14 Dec 2018, 13:59

- In relation to:
MCode4GCC -- C/C++ to MCode Generator - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=4642

- I received an error message when trying to compile C++ code that used the 'bool' type:
C:\Users\me\Desktop\z gcc temp source.c: In function 'inbufstr':
C:\Users\me\Desktop\z gcc temp source.c:5:2: error: unknown type name 'bool'
- I was able to compile if I used '_Bool' instead, however, the code wouldn't run in Visual Studio when using '_Bool'.
- Is there a two-way compatible solution?
- Would it be worth just using char instead, what would be a good alternative that didn't decrease performance, and that wouldn't require any script rewrites (other than changing 'bool').

- When I used '_Bool' the machine code appeared to work, although I got this error, which may or may not be related to types:
C:/TDM-GCC-64/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function `main':
C:/crossdev/src/mingw-w64-v4-git/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
- I pity the bool. Like a bool in a china shop. (C Bool by Paul McCartney.) Thanks for reading.
User avatar
nnnik
Posts: 3685
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: C++: TDM-GCC: error with bool

14 Dec 2018, 14:12

Gcc and VC++ are generally incompatible.
You have to supply different sources using #IF.
Generally I would just drop support for one and choose one to use.
(There are a lot of incompatibilities for example the way you compile against libraries - vs uses some #pragma stuff with some special instructions and gcc expects yu to pass them to the command line)
Recommends AHK Studio
User avatar
jeeswg
Posts: 5555
Joined: 19 Dec 2016, 01:58
Location: UK

Re: C++: TDM-GCC: error with bool

17 Dec 2018, 14:56

- Also, a limitation of C++ compared to AutoHotkey is that you cannot break out of nested loops by doing 'break n'. So instead, I do the equivalent of 'if var then break' within each loop. (I often like to code in AutoHotkey first and then convert to C++.)
- Also again, min/max are not built-in, so I use the ternary operator.
C++: TDM-GCC: minimising includes - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 23&t=59986
- And one must be careful to use == (AHK and C++: comparison) for comparison instead of = (AHK: comparison, C++: assignment).

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 2 guests