编译

作者: 滩主 | 来源:发表于2020-02-10 09:05 被阅读0次

    符号决议

    image.png
    image.png
    image.png

    本质上整个符号表只是想表达两件事:
    我能提供给其它文件使用的符号
    我需要其它文件提供给我使用的符号

    image.png
    image.png
    // add.c
    int global_x = 256;
    char global_c = 'a';
    
    int add(int a,int b)
    {
        return a+b;
    }
    // gcc -c add.c
    // readelf -h add.o
    // readelf -a add.o
    //  readelf -S add.o
    // readelf -r add.o
    // readelf -x .text add.o
    // dumpelf add.o
    

    事关右值

    #include <stdio.h>
    #include <string>
    
    int main()
    {
      std::string str = "hello!";
      printf("%p %p\n",&str[0],&str);
    
      std::string&& r = std::move(str);
      printf("%p\n",&r[0]);
    
      // 短字符串直接存储在栈上,没有new
      std::string str2(std::move(str));
      str[0] = 'H';
      printf("%p %p\n",&str2[0],&str2);
      printf("%s\n",&str2[0]);
    
      std::string long_str = "sdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfweljlnjaljasdf";
      printf("%p %p\n",&long_str[0],&long_str);
      //std::string long_str2(std::move(long_str));
      std::string long_str2 = std::move(long_str);
      printf("%p %p\n",&long_str2[0],&long_str2);
    
      return 0;
    }
    
    #include <utility>
    #include <string>
    #include <iostream>
    #include <vector>
    #include <stdio.h>
    
    int main()
    {
        std::string str = "Helloaaaaaaaaaaaaaaaaaaaaaaaaa";
        printf("%p\n",&str[0]);
        std::vector<std::string> vec;
    
        vec.push_back(str);
        vec.push_back(std::move(str));
        printf("%p\n",&vec[1][0]);
    
        return 0;
    }
    

    https://segmentfault.com/a/1190000016433829
    https://blog.csdn.net/daide2012/article/details/73065204

    相关文章

      网友评论

          本文标题:编译

          本文链接:https://www.haomeiwen.com/subject/lnnoxhtx.html