Problem description

stay C/C++ In development , Use printf Print 64 Bit variables are commonly used , Usually in 32 Bit system %lld Output 64 Bit variables , And in the 64 In the bit system %ld;

If in 32 Bit system %ld Output 64 Bit variable , It is likely that the printed value is abnormal , And in the 64 In the bit system %lld, Compilation errors usually occur , Similar to :

format '%lld' expects type 'long long int', but argument 4 has type 'int64_t'[ -Werror=format=]

If you migrate code across platforms , This is usually the case .


Solution

In order to solve the problem of cross platform migration ,% PRId64 The way of writing solves the problem of cross platform , Mainly to support 32 Bit and 64 Bit operating system .PRId64 Express 64 An integer , stay 32 Bit system long long int, stay 64 Bit system long int.

Writing format :

uint64_t value = 1560;
printf("value = %" PRId64 "\n", value);

The effect is as follows :

uint64_t value = 1560;
printf("value = %" "%ld" "\n", value); // 64bit OS
printf("value = %" "%lld" "\n", value); // 32bit OS

perhaps

uint64_t value = 1560;
printf("value = %ld\n", value); // 64bit OS
printf("value = %lld\n", value); // 32bit OS

Cross platform (32bit and 64bit) Of printf Format symbol %lld Output 64 More related articles on bit solutions

  1. Linux Next printf Format symbol %d、%lld、%llx、%u etc. 【 from CSDN Blog 】

    source :http://blog.csdn.net/anycell/article/details/6966520 %d A signed 32 An integer %lld A signed 64 Bit Certificate %llx A signed 64 position 16 Hexadecimal integer % ...

  2. printf How to output 64 An integer

    From: http://blog.csdn.net/zzqhost/article/details/6064886 About printf Output function 64 Digit problem , Actually in window Lower and linux The next is different ...

  3. go Report errors unimplemented: 64-bit mode not compiled in And mingw 64 Bit installation error ERROR res resolved

    Question 1 :cc1.exe: sorry, unimplemented: 64-bit mode not compiled in Reference resources :https://www.cnblogs.com/lesroad/p/ ...

  4. printf Format output code encyclopedia

    d,lx,ld,,lu, These are all outputs 32 Bit hd,hx,hu, These are all outputs 16 Bit data ,hhd,hhx,hhu, These are all outputs 8 Bit ,lld,ll,llu,llx, These are all outputs 64 Bit , pri ...

  5. printf With %d The problem of formal output floating-point numbers

    If you enter 9876543210l, Then the output of the following program is int main(){ int a;float b,c; scanf("%2d%3f%4f",&a,&a ...

  6. Shan Tan c in printf Format modifier

    I don't say much nonsense , Simply and rudely . ( One ) The initial definition ( Two ) Running results ( 3、 ... and ) Rule summary For the following : printf("%7.4d",12); printf("%4.7f", ...

  7. Linux Kernel sys_call_table、Kernel Symbols Export Table Generation Principle、Difference Between System Calls Entrance In 32bit、64bit Linux

    Catalog . sys_call_table: System call table . Kernel symbol export table :Kernel-Symbol-Table . Linux 32bit.64bit The similarities and differences of system call entry in the environment . Linux 32bi ...

  8. Win7 32bit(x86)/64bit(x64) Full installation version ( Not GHOST edition )

    Windows7 32bit The flagship iso Complete installation image Baidu cloud disk :http://pan.baidu.com/s/1bpjLPs Windows7 64bit The flagship iso Complete installation image Baidu cloud disk :h ...

  9. C Language Printf Format

    Use printf When I printed it, I found , If the data type does not match the type used for printing , The result is chaos . This is because printf It doesn't type data itself , He just outputs the input in a given data format , If they don't match , So because of the different data classes ...

  10. printf Format control details

    format The format of the parameter output , The definition format is %[flags][width][.precision][length]specifier specifier At the back . Defines the data type . Where the s ...

Random recommendation

  1. phpPgAdmin Installation and configuration

    1.phpPgAdmin No installation required , Directly from Sourceforge Download zip , Unzip to “/var/www/” Under folder . After decompressing , To assign root Users and root Group permissions chown -R roo ...

  2. AMQ Learning notes - 21. Send asynchronously

    Original address :Async Sends background ActiveMQ Support synchronization . Asynchronous two sending modes send messages to broker, Mode selection has a huge impact on the transmission delay .producer What kind of output rate can be achieved [1], It is mainly affected by transmission delay ...

  3. JS Code formatting changes the format of the table's values

    In today's cognos It's the first time you need to use JS, It is mainly possible to get the following data when the report page is displayed , I need to check the amount in the type , Later value , accurate 2 Decimal place : There's a percentage , The value is shown as a percentage . as follows . I first tried self ...

  4. Oracle database sys and system The user's default password and how to change it

    Newly installed Oracle database sys The default password of the user is change_on_install,system The default password of the user is manager. If you log in as an administrator , Enter... On the command line sqlplus sys/chang ...

  5. box-shadow example 1

    Instance of a : 1.html <div class="paddingMiddle"> <div class="blank"></div& ...

  6. Mongodb Backup (mongodump) And recovery (mongorestore)

    1. Backup : mongodump -d DbName -o /data/backup 2. recovery : mongorestore -d newDB --drop data/backup/DbName/

  7. Springmvc ModelAndView Step on the pit of HttpServletResponse response

    Start by asking questions . There is a difference between the following two method declarations : @RequestMapping(value = "/rg") public void rg(@PathVariable Long pageI ...

  8. About LP Wizard Generate Allegro Package a pad less solution

    Recently learning Allegro, After installing the software, look at the Internet and say LP Wizard One click build Allegro encapsulation , Just want to have a taste . After all, it's always done manually , I didn't use the guide very much . But follow the online tutorial LP Generated a package , I found that there was no ...

  9. CABAC Summary and supplementary discussion

    In a previous post CABAC We have made a detailed analysis of most of the details of the algorithm , Here is a summary and pick-up . summary CABAC The coding of can be divided into the following four parts : Initialization of context variables Binarization of syntax elements to be encoded Context modeling ( indeed ...

  10. java Basics 68 JavaScript City linkage box ( Web knowledge )

    1. City linkage box <!doctype html> <html> <head> <meta charset="utf-8"> <t ...