2022-01-25

WARNING: This article may be obsolete
This post was published in 2022-01-25. Obviously, expired content is less useful to users if it has already pasted its expiration date.
This article is categorized as "Garbage" . It should NEVER be appeared in your search engine's results.


继续复习C语言

两种include的区别

🔗 [c++ - What is the difference between #include and #include "filename"? - Stack Overflow] https://stackoverflow.com/questions/21593/what-is-the-difference-between-include-filename-and-include-filename

未初始化变量(比如烫烫烫烫烫)

#include<stdio.h>


void print1() {

// print1: 32531
// print1: 0x7ffe0ad5fc6c,每次运行程序得到的结果都可能不一样

    int i;
    printf("print1: %d\n", i);
    printf("print1: %p\n", &i);
}

void print2() {

// print2: 32766
// print2: 0x7ffe0ad5fc6c,每次运行程序得到的结果都可能不一样

    int j;
    printf("print2: %d\n", j);
    printf("print2: %p\n", &j);
}


int main(int argc, char const *argv[]) {

// main(): 0
    int i;
    printf("main(): %d\n\n", i);

    print1();
    printf("\n\n");
    print2();

    return 0;
}

结果(GCC):

main(): 0

print1: 32531
print1: 0x7ffe0ad5fc6c


print2: 32766
print2: 0x7ffe0ad5fc6c

当然,在MSVS的结果应该并不是这样,指针应该会初始化为 0xCCCCCCCC (没有验证过):

https://blog.csdn.net/u010154760/article/details/45176895

关于“烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫”的额外阅读:🔗 [外国人编程出错也会出现「烫烫烫烫」吗?为什么会出现这个? - 知乎] https://www.zhihu.com/question/23600507


computer vision: smoothing window, 和 signal processing: smoothing window(鸽了)

(鸽了)


OCR辅助查找工具

In practice, the difference is in the location where the preprocessor searches for the included file. For #inc lude the preprocessor searches in an implementation dependent manner, normally in search directories pre-designated by the compiler/IDE. This method is normally used to include standard library header files. For #include “filename” the preprocessor searches first in the same directory as the file containing the directive, and then follows the search path used for the #inc Lude form. This method is normally used to include programmer-defined header files.我们在刚学c编程的时候经常碰到”烫烫烫烫烫烫沉烫泛烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫”,这是为什么呢? 先从上次某公司笔试说起,当时有一题是考到了关于变量初始化的问题。在主函数外面(全局)和里面(局部)个定义一个int类型数值。然后没有赋值,直接打印出来,问输出什么。 那会只知道全局默认是o,局部是一个负的挺大的数,还以为是最小整数。回来后试了下,局部的in默认的是-858993460,即NOxcococccc。 但是为什么局部的默认是Oxcccccccc而不是其他的? 查了一些资料,发现VC的DEBUG版会把末初始化的指针自动初始化为Oxcccccccc,而不是就让它随机去,那是因为DEBUC版的目的是为了能让程序员更早的发现错误,把堆栈上 的数据对初始化成了OxGc,也就是说局部变量如果不初始化,那么DEBUC版本中就会是Oxcc,如果野指针的初值不确定。而汉字“烫”的编码恰好就是110010011001100,这也就为什 么初学的时候会出现“烫”了,因为那会经常会忘记赋值或者数组越界了。而全局变量链接时已分配空间,程序运行时,操作系统的加载器,负责把链接器分配给全局变量的虚拟内存空 间,映射到一个初始化为零的页面,所以被初始化为零。全局和静态的默认初始化都是靠加载机制实现的。另外:未初始化的符号在目标文件的bss段中,而初始化的符号在data段中。 局部变量存在于(堆栈)中,全局变量存在于(静态区)中,动态申请数据存在于(堆)中。



 Last Modified in 2022-02-22 

Leave a Comment Anonymous comment is allowed / 允许匿名评论