public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Combo GCC issues with bugs
       [not found] <1564865987.561926.25803.36864@mail.rambler.ru>
@ 2019-08-03 21:02 ` Denis Vnoukov
  2019-08-04 15:00   ` Ken Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Denis Vnoukov @ 2019-08-03 21:02 UTC (permalink / raw)
  To: cygwin

Yes, gcvt is legacy. But there is no one Linux distribution which has no gcvt in
the world.
Moreover gcvt present into MSVC, Intel C, mingw, etc..
It is true to have gcvt with right declaration.
FD_ZERO(&read_fd); <== with -Wold-style-cast produced real bogus and suspicious
warning which looks like bug
GetTickCount64(); <== recommended part of WINAPI and must be avail via windows.h
_BitScanReverse64 and _BitScanForward64 must be with "unsigned long *":
unsigned char _BitScanForward64(
unsigned long * Index,
unsigned __int64 Mask
);
due to ms specification as well...
--
Cheers,
\Denis


  The Linux man page for gcvt says, "Marked as LEGACY in POSIX.1-2001.
  POSIX.1-2008 removes the specification of gcvt(), recommending the use of
  sprintf(3) instead (though snprintf(3) may be preferable)."

  Cygwin's stdlib.h is consistent with this. It guards the declaration of gcvt
  with

  #if __XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112

  If you really need to use gcvt, I think you probably have to #define
  _XOPEN_SOURCE to be 500. (I haven't tested this.)

  > 2. gcvt function in all standards has declaration like:char *gcvt(double
  number,
  > int ndigit, char *buf);but we have a warning about "int-conversion" and get
  core
  > dump on line:printf("buffer: %s", str);

  This is a consequence of the fact that gcvt hasn't been declared.

  I haven't looked at the rest of the warnings/errors in your message, but I
  suspect you can figure out the causes yourself by looking at the relevant
  headers and/or by looking at the result of preprocessing. You might also find
  the following helpful:

  https://cygwin.com/faq.html#faq.programming.64bitporting

  Ken

  --
  Problem reports: http://cygwin.com/problems.html
  FAQ: http://cygwin.com/faq/
  Documentation: http://cygwin.com/docs.html
  Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Combo GCC issues with bugs
  2019-08-03 21:02 ` Combo GCC issues with bugs Denis Vnoukov
@ 2019-08-04 15:00   ` Ken Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Ken Brown @ 2019-08-04 15:00 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1551 bytes --]

[Please don't top post on this list.]

On 8/3/2019 5:02 PM, Denis Vnoukov wrote:
> Yes, gcvt is legacy. But there is no one Linux distribution which has no gcvt in
> the world.
> Moreover gcvt present into MSVC, Intel C, mingw, etc..
> It is true to have gcvt with right declaration.
> FD_ZERO(&read_fd); <== with -Wold-style-cast produced real bogus and suspicious
> warning which looks like bug
> GetTickCount64(); <== recommended part of WINAPI and must be avail via windows.h
> _BitScanReverse64 and _BitScanForward64 must be with "unsigned long *":
> unsigned char _BitScanForward64(
> unsigned long * Index,
> unsigned __int64 Mask
> );
> due to ms specification as well...

There are several mistakes (not GCC bugs) in your program.

1. As I already said in my first message, you need to define the appropriate 
feature-test macro in order to get the declaration of gcvt.  (I suggested 
defining _XOPEN_SOURCE to 500, and that in fact works.)

2. The Microsoft documentation for GetTickCount64 says, "To compile an 
application that uses this function, define _WIN32_WINNT as 0x0600 or later." 
You didn't do this.

3. The Microsoft documentation for _BitScanForward64 says that the first 
argument is of type 'unsigned long *'.  You assumed that Microsoft's unsigned 
long would be the same size as Cygwin's.  You can avoid this problem by using 
ULONG instead of unsigned long.

I'm attaching a fixed version of your program that compiles without warnings and 
runs without crashing on 64-bit Cygwin.

Ken

[-- Attachment #2: main.c --]
[-- Type: text/plain, Size: 514 bytes --]

#define _XOPEN_SOURCE 500
#define _WIN32_WINNT 0x0600

#include <stdlib.h>
#include <stdio.h>
#include <sys/select.h>
#include <windows.h>
#include <stdint.h>
#include <intrin.h>

int
main()
{
  char buf[50];
  char * str = gcvt (3.141592653589793238462643383279502884197169399375, 49, buf);
  printf ("buffer: %s", str);
  fd_set read_fd;
  FD_ZERO (&read_fd);
  GetTickCount64 ();
  ULONG index;
  uint64_t b = 0xbedabedadeadc0de;
  _BitScanForward64 (&index, b);
  _BitScanReverse64 (&index, b);
  return 0;
} 

[-- Attachment #3: Type: text/plain, Size: 219 bytes --]


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Combo GCC issues with bugs
  2019-08-02 21:05 Denis Vnoukov
@ 2019-08-03 18:59 ` Ken Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Ken Brown @ 2019-08-03 18:59 UTC (permalink / raw)
  To: cygwin; +Cc: Denis Vnoukov

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 3961 bytes --]

On 8/2/2019 5:05 PM, Denis Vnoukov wrote:
> Code Example:
> #include <stdlib.h>
> #include <stdio.h>
> #include <sys/select.h>
> #include <windows.h>
> #include <stdint.h>
> #include <intrin.h>int main()
> {
> // https://github.com/msys2/MSYS2-packages/issues/1711
> char buf[50];
> char * str = gcvt(3.141592653589793238462643383279502884197169399375, 49, buf);
> printf("buffer: %s", str);// https://github.com/msys2/MSYS2-packages/issues/1270
> fd_set read_fd;
> FD_ZERO(&read_fd);GetTickCount64();//
> https://github.com/msys2/MSYS2-packages/issues/1262
> unsigned long index;
> uint64_t b = 0xbedabedadeadc0de;
> _BitScanForward64(&index, b);
> _BitScanReverse64(&index, b);return 0;
> }
> If we compile it with gcc as .c:
> $ gcc main.c
> main.c: In function ‘main’:
> main.c:16:15: warning: implicit declaration of function ‘gcvt’
> [-Wimplicit-function-declaration]
> char * str = gcvt(3.141592653589793238462643383279502884197169399375, 49, buf);
> ^~~~
> main.c:16:15: warning: initialization makes pointer from integer without a cast
> [-Wint-conversion]
> main.c:23:2: warning: implicit declaration of function ‘GetTickCount64’; did you
> mean ‘GetTickCount’? [-Wimplicit-function-declaration]
> GetTickCount64();
> ^~~~~~~~~~~~~~
> GetTickCount
> main.c:28:20: warning: passing argument 1 of ‘_BitScanForward64’ from
> incompatible pointer type [-Wincompatible-pointer-types]
> _BitScanForward64(&index, b);
> ^
> In file included from /usr/include/w32api/winnt.h:27:0,
> from /usr/include/w32api/minwindef.h:163,
> from /usr/include/w32api/windef.h:8,
> from /usr/include/w32api/windows.h:69,
> from main.c:8:
> /usr/include/w32api/psdk_inc/intrin-impl.h:749:1: note: expected ‘unsigned int *’
> but argument is of type ‘long unsigned int *’
> __buildbitscan(_BitScanForward64, unsigned __int64, "bsf{q %[Mask],%[Index] |
> %[Index],%[Mask]}")
> ^
> main.c:29:20: warning: passing argument 1 of ‘_BitScanReverse64’ from
> incompatible pointer type [-Wincompatible-pointer-types]
> _BitScanReverse64(&index, b);
> ^
> In file included from /usr/include/w32api/winnt.h:27:0,
> from /usr/include/w32api/minwindef.h:163,
> from /usr/include/w32api/windef.h:8,
> from /usr/include/w32api/windows.h:69,
> from main.c:8:
> /usr/include/w32api/psdk_inc/intrin-impl.h:756:1: note: expected ‘unsigned int *’
> but argument is of type ‘long unsigned int *’
> __buildbitscan(_BitScanReverse64, unsigned __int64, "bsr{q %[Mask],%[Index] |
> %[Index],%[Mask]}")
> ^
> So...
> 1. gcvt function must be into stdlib.h, but we have a warning

The Linux man page for gcvt says, "Marked as LEGACY in POSIX.1-2001. 
POSIX.1-2008 removes the specification of gcvt(), recommending the use of 
sprintf(3) instead (though snprintf(3) may be preferable)."

Cygwin's stdlib.h is consistent with this.  It guards the declaration of gcvt with

   #if __XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112

If you really need to use gcvt, I think you probably have to #define 
_XOPEN_SOURCE to be 500.  (I haven't tested this.)

> 2. gcvt function in all standards has declaration like:char *gcvt(double number,
> int ndigit, char *buf);but we have a warning about "int-conversion" and get core
> dump on line:printf("buffer: %s", str);

This is a consequence of the fact that gcvt hasn't been declared.

I haven't looked at the rest of the warnings/errors in your message, but I 
suspect you can figure out the causes yourself by looking at the relevant 
headers and/or by looking at the result of preprocessing.  You might also find 
the following helpful:

   https://cygwin.com/faq.html#faq.programming.64bitporting

Ken
\0ТÒÐÐ¥\a&ö&ÆVÒ\a&W\x06÷'G3¢\x02\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒ÷\a&ö&ÆV×2æ‡FÖÀФd\x15\x13¢\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒöf\x17\x12ðФFö7VÖVçF\x17F–öã¢\x02\x02\x02\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒöFö72æ‡FÖÀÐ¥Vç7V'67&–&R\x06–æfó¢\x02\x02\x02\x02\x02\x06‡GG\x03¢òö7–wv–âæ6öÒöÖÂò7Vç7V'67&–&R×6–×\x06ÆPРÐ

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Combo GCC issues with bugs
@ 2019-08-02 21:05 Denis Vnoukov
  2019-08-03 18:59 ` Ken Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Denis Vnoukov @ 2019-08-02 21:05 UTC (permalink / raw)
  To: cygwin

Code Example:
#include <stdlib.h>
#include <stdio.h>
#include <sys/select.h>
#include <windows.h>
#include <stdint.h>
#include <intrin.h>int main()
{
// https://github.com/msys2/MSYS2-packages/issues/1711
char buf[50];
char * str = gcvt(3.141592653589793238462643383279502884197169399375, 49, buf);
printf("buffer: %s", str);// https://github.com/msys2/MSYS2-packages/issues/1270
fd_set read_fd;
FD_ZERO(&read_fd);GetTickCount64();//
https://github.com/msys2/MSYS2-packages/issues/1262
unsigned long index;
uint64_t b = 0xbedabedadeadc0de;
_BitScanForward64(&index, b);
_BitScanReverse64(&index, b);return 0;
}
If we compile it with gcc as .c:
$ gcc main.c
main.c: In function ‘main’:
main.c:16:15: warning: implicit declaration of function ‘gcvt’
[-Wimplicit-function-declaration]
char * str = gcvt(3.141592653589793238462643383279502884197169399375, 49, buf);
^~~~
main.c:16:15: warning: initialization makes pointer from integer without a cast
[-Wint-conversion]
main.c:23:2: warning: implicit declaration of function ‘GetTickCount64’; did you
mean ‘GetTickCount’? [-Wimplicit-function-declaration]
GetTickCount64();
^~~~~~~~~~~~~~
GetTickCount
main.c:28:20: warning: passing argument 1 of ‘_BitScanForward64’ from
incompatible pointer type [-Wincompatible-pointer-types]
_BitScanForward64(&index, b);
^
In file included from /usr/include/w32api/winnt.h:27:0,
from /usr/include/w32api/minwindef.h:163,
from /usr/include/w32api/windef.h:8,
from /usr/include/w32api/windows.h:69,
from main.c:8:
/usr/include/w32api/psdk_inc/intrin-impl.h:749:1: note: expected ‘unsigned int *’
but argument is of type ‘long unsigned int *’
__buildbitscan(_BitScanForward64, unsigned __int64, "bsf{q %[Mask],%[Index] |
%[Index],%[Mask]}")
^
main.c:29:20: warning: passing argument 1 of ‘_BitScanReverse64’ from
incompatible pointer type [-Wincompatible-pointer-types]
_BitScanReverse64(&index, b);
^
In file included from /usr/include/w32api/winnt.h:27:0,
from /usr/include/w32api/minwindef.h:163,
from /usr/include/w32api/windef.h:8,
from /usr/include/w32api/windows.h:69,
from main.c:8:
/usr/include/w32api/psdk_inc/intrin-impl.h:756:1: note: expected ‘unsigned int *’
but argument is of type ‘long unsigned int *’
__buildbitscan(_BitScanReverse64, unsigned __int64, "bsr{q %[Mask],%[Index] |
%[Index],%[Mask]}")
^
So...
1. gcvt function must be into stdlib.h, but we have a warning
2. gcvt function in all standards has declaration like:char *gcvt(double number,
int ndigit, char *buf);but we have a warning about "int-conversion" and get core
dump on line:printf("buffer: %s", str);
3. We have a warning about "implicit declaration of function" GetTickCount64();But
it can be available with windows.hhttps://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-gettickcount64
4. We have a warning about "incompatible pointer type" for _BitScanForward64 and
_BitScanReverse64 functions.But declaration from Microsoft looks like:unsigned
char _BitScanForward64( unsigned long * Index, unsigned __int64 Mask );https://docs.microsoft.com/en-us/cpp/intrinsics/bitscanforward-bitscanforward64?view=vs-2019
Then, let's compile source via g++ with -Wold-style-cast option as .cpp:
$ g++ -Wold-style-cast main.cpp
main.cpp: In function ‘int main()’:
main.cpp:16:15: error: ‘gcvt’ was not declared in this scope
char * str = gcvt(3.141592653589793238462643383279502884197169399375, 49, buf);
^~~~
In file included from /usr/include/sys/types.h:52:0,
from /usr/include/stdio.h:61,
from main.cpp:6:
main.cpp:21:11: warning: use of old-style cast [-Wold-style-cast]
FD_ZERO(&read_fd);
^
main.cpp:23:2: error: ‘GetTickCount64’ was not declared in this scope
GetTickCount64();
^~~~~~~~~~~~~~
main.cpp:23:2: note: suggested alternative: ‘GetTickCount’
GetTickCount64();
^~~~~~~~~~~~~~
GetTickCount
main.cpp:28:29: error: cannot convert ‘long unsigned int*’ to ‘unsigned int*’ for
argument ‘1’ to ‘unsigned char _BitScanForward64(unsigned int*, long long
unsigned int)’
_BitScanForward64(&index, b);
^
main.cpp:29:29: error: cannot convert ‘long unsigned int*’ to ‘unsigned int*’ for
argument ‘1’ to ‘unsigned char _BitScanReverse64(unsigned int*, long long
unsigned int)’
_BitScanReverse64(&index, b);

So...1. error: ‘gcvt’ was not declared in this scopebut it must be into stdlib.h
as well:MSVC:
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/gcvt?view=vs-2019
Linux man: http://man7.org/linux/man-pages/man3/gcvt.3.html
And from IBM:
https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.3.0/com.ibm.zos.v2r3.bpxbd00/rgcvt.htm
2.main.cpp:21:11: warning: use of old-style cast [-Wold-style-cast]
FD_ZERO(&read_fd);This is bullshit.
3. error: ‘GetTickCount64’ was not declared in this scopeSee Above.
4. For BitScanForward64/_BitScanReverse64 - error: cannot convert ‘long unsigned
int*’ to ‘unsigned int*’ for argument ‘1’See Above.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-08-04 15:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1564865987.561926.25803.36864@mail.rambler.ru>
2019-08-03 21:02 ` Combo GCC issues with bugs Denis Vnoukov
2019-08-04 15:00   ` Ken Brown
2019-08-02 21:05 Denis Vnoukov
2019-08-03 18:59 ` Ken Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).