zoukankan      html  css  js  c++  java
  • C99 to C89

    Reality is, many of these C language features are cosmetic extensions introduced in C99 that are trivially emulated using classic C89 syntax. Consider designated initializers:

    struct {
        int a, b;
    } var = { .b = 1, };

    This can be trivially emulated in C89 by using the following syntax:

    struct {
        int a, b;
    } var = { 0, 1 };

    For unions, you can change the initialization (as long as the size of the first field is large enough to hold the contents of any other field in the union) to do a binary translation of the initialized field type to the first field type:

    union {
        unsigned int a;
        float b;
    } var = { .b = 1.0, };

    becomes:

    union {
        unsigned int a;
        float b;
    } var = { 0x3f800000, };

    Here, 0x3f800000 is the binary representation of the floating point number 1.0. If the value to be converted is not static, the assignment can simply become a statement on its own:

    union {
        unsigned int a;
        float b;
    } var;
    var.b = 1.0;

    Other C99 language features (e.g. compound literals) can be translated in a similar manner:

    struct {
        int *list;
    } var = { (int *) { 0, 1 } };

    becomes:

    int *list = { 0, 1 };
    struct {
        int *list;
    } var = { list };
  • 相关阅读:
    sessionStorage用于分页,瀑布流和存储用户数据等
    js瀑布流
    sql 日结
    js 去除html标签
    c# 去除文本的html标签
    jQuery 数据滚动(上下)
    jQuery 图片随滚动条滚动加载
    sql 指定范围 获取随机数
    js 时间格式化
    js自写字符串 append 方法
  • 原文地址:https://www.cnblogs.com/weinyzhou/p/2808478.html
Copyright © 2011-2022 走看看