NO

Author Topic: Intrin header issue?  (Read 2667 times)

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 189
    • Bcx Basic to C/C++ Translator
Intrin header issue?
« on: January 27, 2023, 03:08:23 AM »
I wanted to see if GnuChess, which was converted to BCX 20 years ago, could compile with our
latest tools.  After about an hour of editing, the latest BCX produced C source that compiled without
warnings or errors with Lcc-Win32.

If I remove intrin.h (unused) from BcxChess.c, Pelles v11 also compiles, with only a
handful of warnings.  Then the program seems to run okay but I didn't test every aspect of it.

bcxchess.c(1872): warning #2243: Check precedence for operator '&'; use parentheses to clarify.
bcxchess.c(2040): warning #2243: Check precedence for operator '|'; use parentheses to clarify.
bcxchess.c(2338): warning #2243: Check precedence for operator '&'; use parentheses to clarify.
bcxchess.c(2401): warning #2243: Check precedence for operator '&'; use parentheses to clarify.
bcxchess.c(5623): warning #2808: Operation on 'a' may be undefined.
bcxchess.c(5637): warning #2808: Operation on 'a' may be undefined.

The point to this bug report:

If intrin.h is not removed from BcxChess.c, the following errors occur:

Code: [Select]

C:\Pellesc\Include\xmmintrin.h(286): error #2120:
Redeclaration of '_mm_prefetch', previously declared at C:\Pellesc\Include\Win\winnt.h(2707);
expected 'void __cdecl function(const char *, int)' but found 'void __cdecl function(char *, int)'.


C:\Pellesc\Include\intrin.h(269): error #2120:
Redeclaration of '_bittest', previously declared at C:\Pellesc\Include\Win\winnt.h(2317);
expected 'unsigned char __cdecl function(const long int *, long int)' but found 'unsigned char __cdecl function(long int *, long int)'.


C:\Pellesc\Include\intrin.h(92): error #2120:
Redeclaration of 'strlen', previously declared at C:\Pellesc\Include\string.h(38);
expected 'unsigned int __cdecl function(const char *)' but found 'unsigned int __cdecl function(char *)'.


C:\Pellesc\Include\intrin.h(93): error #2120:
Redeclaration of 'strcpy', previously declared at C:\Pellesc\Include\string.h(36);
expected 'char * __cdecl function(char * restrict, const char * restrict)' but found 'char * __cdecl function(char * restrict, char * restrict)'.


C:\Pellesc\Include\intrin.h(94): error #2120:
Redeclaration of 'strcmp', previously declared at C:\Pellesc\Include\string.h(35);
expected 'int __cdecl function(const char *, const char *)' but found 'int __cdecl function(char *, char *)'.


C:\Pellesc\Include\intrin.h(97): error #2120:
Redeclaration of 'wcslen', previously declared at C:\Pellesc\Include\wchar.h(96);
expected 'unsigned int __cdecl function(const wchar_t *)' but found 'unsigned int __cdecl function(wchar_t *)'.


C:\Pellesc\Include\intrin.h(98): error #2120:
Redeclaration of 'wcscpy', previously declared at C:\Pellesc\Include\wchar.h(88);
expected 'wchar_t * __cdecl function(wchar_t * restrict, const wchar_t * restrict)' but found 'wchar_t * __cdecl function(wchar_t * restrict, wchar_t * restrict)'.


C:\Pellesc\Include\intrin.h(99): error #2120:
Redeclaration of 'wmemcpy', previously declared at C:\Pellesc\Include\wchar.h(112);
expected 'wchar_t * __cdecl function(wchar_t * restrict, const wchar_t * restrict, unsigned int)' but found 'wchar_t * __cdecl function(wchar_t * restrict, wchar_t * restrict, unsigned int)'.


It's not a big deal but I thought it was worth reporting.  - Thanks!
« Last Edit: January 27, 2023, 03:57:03 AM by MrBcx »
Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Intrin header issue?
« Reply #1 on: March 05, 2023, 04:46:24 PM »
Well, is there something to actually test with? No obvious problems here mixing f.e. <windows.h> with <intrin.-h>. The other warnings could very well be correct...
/Pelle

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 189
    • Bcx Basic to C/C++ Translator
Re: Intrin header issue?
« Reply #2 on: March 05, 2023, 07:01:52 PM »
Well, is there something to actually test with? No obvious problems here mixing f.e. <windows.h> with <intrin.-h>. The other warnings could very well be correct...
Hi Pelle,

Attached is BcxChess.zip.

BCX created BcxChess.c  ( included in the zip )

I've manually edited BcxChess.c at line 300 by commenting out   #include <intrin.h>

Compiling with Pelles C v11 using the included build.bat and pw32.bat,
I get the warnings mentioned previously, but not the errors, and BcxChess.exe executes correctly.

If I uncomment  #include <intrin.h>, the build blows up.

I can successfully compile hundreds of BCX samples using Pelles C, all of which contain #include <intrin.h>
in the boilerplate, and do not exhibit the errors seen compiling BcxChess.

I've concluded this is one-off, so don't waste your time on this unless you feel like solving a puzzle.   ;)
Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: Intrin header issue?
« Reply #3 on: March 05, 2023, 09:06:33 PM »
I've concluded this is one-off, so don't waste your time on this unless you feel like solving a puzzle.   ;)
I just like to understand enough, since unusual behavior could mean a bug...

In "gnuchess.h" (line 29) there is:
Code: [Select]
#define constwhich seems to explain the disappearing "const" in <intrin.h>

For a construct like this (f.e. line 5623 in bcxchess.c):
Code: [Select]
a[u]=++a[u]|c;there are issues with what C calls "sequence points". With a (not terribly up-to-date) version of GCC I get a similar warning. I stopped analyzing after that.

For a construct like this (f.e. line 2338 in bcxchess.c):
Code: [Select]
in_square=(row(bking)>=r&distance(sq,bking)<8-r)the use of '&' is a bit odd (but should work here).
For this case, something like:
Code: [Select]
in_square=(row(bking)>=r && distance(sq,bking)<8-r)would be even more understandable.
/Pelle

Offline MrBcx

  • Global Moderator
  • Member
  • *****
  • Posts: 189
    • Bcx Basic to C/C++ Translator
Re: Intrin header issue?
« Reply #4 on: March 05, 2023, 10:47:09 PM »
Well done sir, and a speedy bit of detective work as well.

Yes, commenting out #define const in gnuchess.h leads to a successful compile.

To your other point, BCX has the ANDALSO keyword which forces a logical "and" rather than
a bitwise "and".   ANDALSO did not exist in BCX 20-odd years ago when this port took place.
The fact that Pelles C still compiles this chess game into a working executable is a testament
to the stability and reliability of your tools.  They are always a pleasure to work with. 

Many Thanks!

Bcx Basic to C/C++ Translator
https://www.BcxBasicCoders.com

Offline Vortex

  • Member
  • *
  • Posts: 864
    • http://www.vortex.masmcode.com
Re: Intrin header issue?
« Reply #5 on: March 06, 2023, 07:48:45 PM »
Hi MrBcx,

Very nice work.
Code it... That's all...