[C] zlstdint (enable compilers such as VC and TC to automatically be compatible with the C99 Integer type) V1.0. Supports the compiler for DOS such as Turbo C ++, zlstdintc99

Source: Internet
Author: User

[C] zlstdint (enable compilers such as VC and TC to automatically be compatible with the C99 Integer type) V1.0. Supports the compiler for DOS such as Turbo C ++, zlstdintc99

Author: zyl910

In the past, I wrote a c99int library for Intelligent Processing (http://www.cnblogs.com/zyl910/p/c99int_v102.html) in order to allow the VC ++ compiler to support the C99 Integer type ). Nowadays, a major change has been made to be compatible with the DOS compiler such as Turbo C ++ 3, and it is no longer suitable to use the old name, so zlstdint is adopted.


I. Usage Overview

The usage is very simple-put the z_stdint.h and z_inttyp.h files in your project, you can use the C99 Integer type and related macros normally.

Sample Code --

#define __STDC_LIMIT_MACROS#define __STDC_CONSTANT_MACROS#define __STDC_FORMAT_MACROS#include <stdio.h>#include "z_stdint.h"#include "z_inttyp.h"/// main.int main(int argc, char* argv[]) {    uint8_t i8 = (uint8_t)INT8_C(-1);    uint16_t i16 = (uint16_t)INT16_C(-1);    uint32_t i32 = (uint32_t)INT32_C(-1);#ifdef INT64_MAX    uint64_t i64 = (uint64_t)INT64_C(-1);#endif#ifdef INT64_MAX    printf("stdint:\t%" PRIu8 ", %" PRIu16 ", %" PRIu32 ", %" PRIu64 "\n", i8, i16, i32, i64);#else    printf("stdint:\t%" PRIu8 ", %" PRIu16 ", %" PRIu32 "\n", i8, i16, i32);#endif    return 0;}

 

Because the old compiler does not support the 64-bit integer type, it determines whether to support the INT64_MAX macro.


Ii. Change details

To support the DOS compiler such as Turbo C ++ 3, the header file name is carefully designed to comply with the naming rules for 8.3 file names. File Name ing is --
Z_stdint.h: corresponds to "stdint. h" in the C99 standard ".
Z_inttyp.h: corresponds to "inttypes. h" in the C99 standard ".

Use the "z _" prefix to indicate that it is used to be compatible with header files in the C standard. The subsequent six letters are abbreviations of the corresponding header files.

Since the old compilers such as Turbo C ++ 3 do not support the 64-bit integer type, zlstdint has also been adjusted accordingly-if it is found that the compiler does not support the 64-bit integer type, the standard 64-bit integer type (int64_t, uint64_t, int_least64_t…) will not be defined ......) And corresponding macros (INT64_MAX, UINT64_MAX ......), The maximum integer types such as intmax_t are limited to 32 bits. To detect this situation, zlstdint provides a Z_STDINT_INTMAX_BIT (number of digits of the intmax_t type) Macro.

Given that automatically identifying compiler code may lead to misjudgment, these configuration macros are provided --
Z_STDINT_H_USESYS: whether the stdint. h. Provided by the compiler is used.
Z_INTTYP_H_USESYS: whether inttypes. h. Provided by the compiler is used.

 

Iii. Test Results

Tested the following compilers --

* Virtual C ++: 6, 7.1 (2003), 8 (2005), 9 (2008), 10 (2010), 11 (2012), 12 (2013 ).
* Turbo C ++: Turbo C ++ 3, Borland C ++ 3.1, C ++ Builder 6, C ++ Builder XE3.
* GCC (Linux): 4.7.0 ~ 4.8.2 (Fedora 17 ~ 20), 4.6.3 ~ 4.8.2 (Ubuntu 12.04 ~ 14.04 ).
* GCC (MinGW): 4.6.2 (MinGW (20120426), 4.7.1 ~ 4.9.2 (TDM-GCC )).
* Llvm gcc: 4.2 (Mac OS x Lion 10.7.4), 4.2.1 (Mac OS X Mountain Lion 10.8.3 ).

For example, it is compiled through --

 

References
~~~~~~~~

ISO/IEC 9899: 1999 (C99). ISO/IEC, 1999. Www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
C99 standard. Yourtommy. Http://blog.csdn.net/yourtommy/article/details/7495033
[C/C ++] show the predefined macros of various C/C ++ compilers (C11 standard, C ++ 11 standard, VC, BCB, Intel, GCC). http://www.cnblogs.com/zyl910/archive/2012/08/02/printmacro.html
[C] Let VC, BCB support C99 Integer type (stdint. h, inttypes. h) (compatible with GCC). http://www.cnblogs.com/zyl910/archive/2012/08/08/c99int.html
[C] Let VC support C99 Integer type V1.01. To avoid directory inclusion problems, renamed auto_stdint.h, auto_inttypes.h (in VC6 to VC2012, GCC, BCB and other Compiler Test through). http://www.cnblogs.com/zyl910/archive/2013/01/10/c99int_v101.html
[C] c99int (enable compilers such as VC to automatically be compatible with the C99 Integer type) V1.02. Source code managed to github, add CMake to compile the configuration file, use doxygen specification notes ". http://www.cnblogs.com/zyl910/p/c99int_v102.html

 

Download source code --
Https://github.com/zyl910/zlstdint

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.