Giter Club home page Giter Club logo

notes's Introduction

这是我的 Notes/Wiki。在线查看:http://tangzx.qiniudn.com/notes

                                                          +-------------------+
                                                          |                   |
                                                          | How To Contribute |
                                                          |                   |
                                                          +-------------------+

请以处女座的标准排版自己的文字。至少遵循下面的要求:

-   关于中英文:请手工加上中英文间的空格。

-   关于格式:

    1.  Markdown 格式书写,请遵循如下准则:

        加粗用**加粗**,斜体用*斜体*,加粗并斜体用***加粗并斜体***。

        上标:x^2^ + y^2^ = z^2^

        下标:H~2~O

        >   这是引用。

        |   这是诗句(自然换行)。

        [链接标题](链接路径)

        ![图片 caption](图片路径)

        ![还可以加上一点 CSS](图片路径){align=right}

        列表的使用如下:

            -   无序列表 item 1
            -   无序列表 item 2

        下面则是有序列表:

            1.  one
            2.  two

        或者这样也是可以的:

            #.  still one
            #.  still two

        列表可以嵌套:

            1.  one
                -   11
                -   12
            2.  two

        当然,我倾向于更易于辨识的:

            1.  one

                -   11
                -   12

            2.  two

        缩进永远用 4 个空格,所以不要这样写:

            - 糟糕的无序列表 item 1
            - 糟糕的无序列表 item 2

        更多格式说明见 pandoc 文档:https://github.com/jgm/pandoc/blob/master/MANUAL.txt

        注:我几乎完全同意 jgm 的排版细节,除了:

        1.  H1~H6 两边都括起来:我用 `# header' 而不用 `# header #'
        2.  两个空格代表句子结束:我用 `Hello. Where are you?' 而不用 `Hello.  Where are you?'
        3.  用缩进表示代码块:我用

                下面是一点 C++ 代码:

                ```cpp
                std::cout << "explicit is better than implicit.\n";
                ```

            而不用

                下面是一点 C++ 代码:

                    std::cout << "explicit is better than implicit.\n";

    2.  内容折叠

        内容折叠是一种信息隐藏(褒义)手段。不能折叠内容会导致某种程度的【信息过度接收 panic】,
        它损害了一个好的笔记原有的清晰的层次结构。所以本笔记提供内容折叠功能。

        在 Emacs org-mode 格式中,它被称为 drawer。

        内容折叠主要用于 <dt><dd> 组合中。只需在 Markdown 源码 <dt> 行的最末尾添加“-<”或“+<”。
        前者初始为关闭,后者为打开。两种 drawer 都可以 toggle 其中的内容。
        例子如下:

            这个抽屉默认折叠起来 -<

            :   这是抽屉里面的内容。

                内容。

                内容……

                嵌套一个默认打开的折叠抽屉 +<

                :   这是抽屉里面的内容。

                    内容。

                    内容……

                    内层完。

                外层完。

            这不是个“抽屉”,因为不具备 toggle “内容”的功能。

            :   内容。

        注意:Pandoc 要求源码中 <dt> 块只能是单行。

    3.  引入其它文件

        在文本中使用 `@include <-=path/to/file='

        “@”前面的符号会 prepend 到 included 文件的每一行。
        “-”和“=”之间可以插入额外的字符。

        示例:

        +-----------------------------------------------+
        |                                               |
        |   -   include code                            |
        |                                               |
        |       :   ```cpp                              |
        |           @include <-=2016/democode.cpp=      |
        |           ```                                 |
        |                                               |
        |   -   include excerpts                        |
        |                                               |
        |       @include <-|   =2016/poem.txt=          |
        |                                               |
        +-----------------------------------------------+

        如果 2016/democode.cpp(目录从 repo 根目录起)内容如下:

        +------------------------2016/democode.cpp------+
        |                                               |
        |   #include <stdio.h>                          |
        |                                               |
        |   int main() {                                |
        |       printf( "hello world.\n" );             |
        |   }                                           |
        |                                               |
        +-----------------------------------------------+

        如果 2016/poem.txt 内容如下:

        +------------------------2016/poem.txt----------+
        |                                               |
        |   Like tears                                  |
        |   in the rain.                                |
        |                                               |
        +-----------------------------------------------+

        include 后的效果如下:

        +-----------------------------------------------+
        |                                               |
        |   -   include code                            |
        |                                               |
        |       :   ```cpp                              |
        |           #include <stdio.h>                  |
        |                                               |
        |           int main() {                        |
        |               printf( "hello world.\n" );     |
        |           }                                   |
        |           ```                                 |
        |                                               |
        |   -   include excerpts                        |
        |                                               |
        |       |   Like tears                          |
        |       |   in the rain.                        |
        |                                               |
        +-----------------------------------------------+

        引入语法支持嵌套,且能正确处理“环”的问题。

notes's People

Contributors

1to1 avatar district10 avatar dvorak4tzx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

notes's Issues

位运算

#include <stdio.h>

#define PRINT(x) printf("hex: 0x%08x, dec: %12d, str: \"%s\"\n", x, x, #x)

int main()
{
    puts( "全 0 & 全 1" );
    PRINT( 0 );
    PRINT( -1 );

    puts( "\n全 1 的左右 shift" );
    PRINT( -1>>1 );
    PRINT( -1<<1 );

    puts( "\n减法优先级更高" );
    PRINT( 1<<31-1 );
    PRINT( 1<<30 );

    puts( "\n怎么得到 int 的最大正数" );
    PRINT( 1<<31 );
    PRINT( (1<<31)-1 );
    PRINT( ((unsigned int)1<<31)-1 );
    PRINT( ((unsigned int)-1)>>1 );
    PRINT( -1>>1 );
    PRINT( 0x7FFFFFFF );
}

编译:gcc test.c -o test

运行:./test

结果:

全 0 & 全 1
hex: 0x00000000, dec:            0, str: "0"
hex: 0xffffffff, dec:           -1, str: "-1"

全 1 的左右 shift
hex: 0xffffffff, dec:           -1, str: "-1>>1"
hex: 0xfffffffe, dec:           -2, str: "-1<<1"

减法优先级更高
hex: 0x40000000, dec:   1073741824, str: "1<<31-1"
hex: 0x40000000, dec:   1073741824, str: "1<<30"

怎么得到 int 的最大正数
hex: 0x80000000, dec:  -2147483648, str: "1<<31"
hex: 0x7fffffff, dec:   2147483647, str: "(1<<31)-1"
hex: 0x7fffffff, dec:   2147483647, str: "((unsigned int)1<<31)-1"
hex: 0x7fffffff, dec:   2147483647, str: "((unsigned int)-1)>>1"
hex: 0xffffffff, dec:           -1, str: "-1>>1"
hex: 0x7fffffff, dec:   2147483647, str: "0x7FFFFFFF"

不要被别人的 memset(buf, -1, sizeof(buf)) 迷惑了

有文件 test.c

#include <stdio.h>
#include <string.h>

int main()
{
    int m[2];
    printf( "sizeof(m): %lu\n", sizeof(m) );

    memset( m, -1, sizeof(m) );
    printf( "after memset(m,   -1, sizeof(m)): %20d (0x%08x), %20d (0x%08x)\n", m[0], m[0], m[1], m[1] );

    memset( m,  1, sizeof(m) );
    printf( "after memset(m,    1, sizeof(m)): %20d (0x%08x), %20d (0x%08x)\n", m[0], m[0], m[1], m[1] );

    memset( m, 0xFF, sizeof(m) );
    printf( "after memset(m, 0xFF, sizeof(m)): %20d (0x%08x), %20d (0x%08x)\n", m[0], m[0], m[1], m[1] );

    memset( m, 0xA5, sizeof(m) );
    printf( "after memset(m, 0xA5, sizeof(m)): %20d (0x%08x), %20d (0x%08x)\n", m[0], m[0], m[1], m[1] );
}

编译运行

$ gcc test.c -o test
$ ./test
sizeof(m): 8
after memset(m,   -1, sizeof(m)):                   -1 (0xffffffff),                   -1 (0xffffffff)
after memset(m,    1, sizeof(m)):             16843009 (0x01010101),             16843009 (0x01010101)
after memset(m, 0xFF, sizeof(m)):                   -1 (0xffffffff),                   -1 (0xffffffff)
after memset(m, 0xA5, sizeof(m)):          -1515870811 (0xa5a5a5a5),          -1515870811 (0xa5a5a5a5)

所以,要小心了。别人用 memset(buf, -1, sizeof(buf)) 来初始化 buf,你用 -2 可不是 -2 啊!

这涉及到 two's compliment 编码。


另一个不符合直觉的是 int buf[50] = { 0 }; 确实会把所有元素初始化为 0,但是 int buf[50] = { 3 }; 只回初始化第一个元素为 3,其它都是 0……至少在我的 gccg++ 上都是如此。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.