From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 61750 invoked by alias); 24 May 2017 12:00:47 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 61137 invoked by uid 89); 24 May 2017 12:00:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=3.1 required=5.0 tests=AWL,BAYES_40,KAM_LAZY_DOMAIN_SECURITY,LIKELY_SPAM_SUBJECT,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD autolearn=no version=3.3.2 spammy=H*F:D*no, addressee, Via, H*M:ngi X-HELO: mailgw1.ngi.no Received: from mailgw1.ngi.no (HELO mailgw1.ngi.no) (193.156.4.35) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 24 May 2017 12:00:18 +0000 Received: from casmbx02.oslo.ngi.no ([172.20.15.44]) by epostgw1.ngi.no with ESMTP/TLS/AES256-SHA; 24 May 2017 14:00:17 +0200 Received: from CASMBX02.oslo.ngi.no (172.20.15.44) by CASMBX02.oslo.ngi.no (172.20.15.44) with Microsoft SMTP Server (TLS) id 15.0.1076.9; Wed, 24 May 2017 14:00:16 +0200 Received: from CASMBX02.oslo.ngi.no ([fe80::2c6f:913:5b3a:fc61]) by CASMBX02.oslo.ngi.no ([fe80::2c6f:913:5b3a:fc61%18]) with mapi id 15.00.1076.000; Wed, 24 May 2017 14:00:16 +0200 From: Carl Fredrik Forsberg To: "cygwin@cygwin.com" Subject: FW: Printing long int in C program under cygwin64 Date: Wed, 24 May 2017 12:18:00 -0000 Message-ID: <6f28f46906804c6f8f6b4b861e202492@CASMBX02.oslo.ngi.no> x-ms-exchange-transport-fromentityheader: Hosted Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-SW-Source: 2017-05/txt/msg00387.txt.bz2 I am experiencing problems printing long int values under cygwin64 installe= d on a Windows 10 machine. Below is a test program followed by its output to demonstrate the problem. = The program was initially written to demonstrate the output from lrint(), a= nd developed further to demonstrate to myself how negative integers are tac= kled by printf type specifiers (e.g. %li, %ld etc). My understanding is that lrint() should return a long int. However I am una= ble to get printf to print the correct number. Instead its output is treate= d as an unsigned integer. Any help or hints would be much appreciated. Regards Carl Fredrik #include /* printf */ #include /* lrint */ int main () { char text[64]; printf ( "int -2 =3D %i\n", -2 ); printf ( "int -1 =3D %i\n", -1 ); printf ( "int 0 =3D %i\n", 0 ); printf ( "int 1 =3D %i\n", 1 ); printf ( "long int -2 =3D %li\n", -2 ); printf ( "long int -1 =3D %li\n", -1 ); printf ( "type cast -1 =3D %li\n", (long int)-1 ); printf ( "type cast lrint(-1.0) =3D %li\n", (long int)lrint(-1.0) ); printf ( "lrint(-1.0) =3D %li\n", lrint(-1.0) ); printf ( "lrint(1.0) =3D %li\n", lrint(1.0) ); printf ( "long int 0 =3D %li\n", 0 ); printf ( "long int 1 =3D %li\n", 1 ); sprintf( text,"long int -1 =3D %li", -1 ); printf ( "Via sprintf: %s\n", text); printf ( "size of long int: %i\n", sizeof(long int)); printf ( "size of int: %i\n", sizeof(int)); return 0; } compiled by: gcc lrint_test.c -o lrint_test.exe Output: int -2 =3D -2 int -1 =3D -1 int 0 =3D 0 int 1 =3D 1 long int -2 =3D 4294967294 long int -1 =3D 4294967295 type cast -1 =3D -1 type cast lrint(-1.0) =3D 4294967295 lrint(-1.0) =3D 4294967295 lrint(1.0) =3D 1 long int 0 =3D 0 long int 1 =3D 1 Via sprintf: long int -1 =3D 4294967295 size of long int: 8 size of int: 4 gcc version: gcc (GCC) 5.4.0 Copyright (C) 2015 Free Software Foundation, Inc. The confidentiality or integrity of this message can not be guaranteed foll= owing transmission on the Internet. The addressee should be aware of this b= efore using the contents of this message. -- 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