asked    Joanne     2018-10-22       c       78 view        1 Answer

[SOLVED] warning on 64bit string formatter in mingw environment

What is the correct way to avoid warnings on 64bit printf/scanf arguments on the most recent versions of mingw-w64?

I know that mingw-w64 relies on microsoft runtime for many standard library functions, and that these functions are not compatible with C99 standard.

Old answers say to use %I64d, but as the C99 standard is %lld, anyway if I compile with -Wall -pedantic I get warning for BOTH syntax, here is a small example:

#include <stdio.h>

int main(void)
{
    long long test;
    scanf("%I64d", &test);
    scanf("%lld", &test);
}

Compile it with gcc (my version is mingw-w64 5.0.4, gcc 8.2.0):

x86_64-w64-mingw32-gcc -o test.exe test.c -Wall -pedantic

It gives the following warnings:

dev:tmp dev$ x86_64-w64-mingw32-gcc -o test.exe test.c -Wall -pedantic
test.c: In function ‘main’:
test.c:6:11: warning: ISO C does not support the ‘I64’ ms_scanf length modifier [-Wformat=]
     scanf("%I64d", &test);
           ^~~~~~~
test.c:6:11: warning: ISO C does not support the ‘I64’ ms_scanf length modifier [-Wformat=]
test.c:7:14: warning: unknown conversion type character ‘l’ in format [-Wformat=]
     scanf("%lld", &test);
              ^
test.c:7:11: warning: too many arguments for format [-Wformat-extra-args]
     scanf("%lld", &test);
           ^~~~~~
test.c:7:14: warning: unknown conversion type character ‘l’ in format [-Wformat=]
     scanf("%lld", &test);
              ^
test.c:7:11: warning: too many arguments for format [-Wformat-extra-args]
     scanf("%lld", &test);
           ^~~~~~

Removing -Wall removes both warnings, without -pedantic I can compile without warnings line 6 (%I64d) but not line 7 (%lld).

  1 Answer  

        answered    Charlotte     2018-10-22      

If you want to compile to Microsoft platform, you cannot be pedantic about following the standard. Embrace, extend (and extinguish)! Remove the -pedantic or get a proper C99/C11/C17 implementation.


C89 does not support %lld. It seems you need to disable -Wformat if you happen to target a library that supports it as an extension.





Your Answer





 2018-10-22         Sidney

Date format in Node

I just want to help with the print date like below.Thu Sep 06 2018 18:18:26 GMT+0530I used console.log(new Date())but Output of that is 2018-09-06T12:48:25.776ZSo, I don't know how to convert it. Thanks in advance. :) I used dateformat (npm install --save dateformat):const dateFormat = require('dateformat');console.log(dateFormat(new Date(), "ddd mmm dd yyyy HH:MM:ss UTC" ));Hope it helps. [XXX]You could use some third party module to do that, like moment or date-fns. Or create the string manually.For moment, see this: https://momentjs.com/docs/#/displaying/For date-f...
 node.js                     2 answers                     53 view
 2018-10-22         Ella

es6 class methods can't reach this instance

So I made a class and have no idea why I can't reach this instance inside one method.So in my router I'm calling the method like thisimport Emails from '../controllers/emails'import router from 'express'....route.post('/', Emails.setupEmail)so after calling POST method it calls setupEmail method but it crashes with the message: TypeError: Cannot read property 'availableEmailTypes' of undefinedand the code of class:class Emails {constructor() { this.availableEmailTypes = ['registration', 'forgot-password', 'two-factor']}setupEmail(req, res) { if (!req.body.type || !re...
 javascript                     1 answers                     54 view
 2018-10-22         Dennis

How to return data from inside promise.all

findCustomerOrders(customerId) { return APIService.getCustomerOrders(this, customerId) .then((data) => { data.map(order => { return Promise.all([APIService.getShippingAddress(this, order.id), APIService.getProducts(this,order.id), APIService.getCustomerById(this, customerId)]) .then((returnedData)=>{ return buildOrder(returnedData); }); }); }); }The function where the data is to be returned isfindCustomerOrders(1).then((final) =>{console.log(final)});I have to return the data which is returned by buil...
 node.js                     4 answers                     55 view