杂谈:所见非所得

简介

这里简单评论一些所见非所得的代码,设计。。。
可能导致初学者的抗拒。

Kernel相关

barrier 宏

https://blog.csdn.net/qq_36428903/article/details/124543474
这里的barrier函数其实根据字面理解的意思,不能理解其真正的含义。需要有额外的修饰词,才能完整的表达其含义。

clone 函数

#所见非所得# CLONE在这里指clone函数而非克隆的意思 FILES的含义是共享文件
在这里插入图片描述
https://blog.csdn.net/qq_36428903/article/details/124564276
这个函数被改成了:IDTENTRY_SYSVEC形式的定义;新的方式,有一个特性就是:所见非所得。导致对于新手来说非常的不友好,检索起来非常的麻烦。怎么让IDE可以索引这种形式的函数?

iostat

Systems Performance Enterprise and the Cloud
这本书里也有提到这么个例子;
The name “iostat” is short for “I/O statistics,” although it might have been better to call it “diskiostat” to reflect the type of I/O it reports. This has led to occasional confusion when a user knows that an application is performing I/O (to the
file system) but wonders why it can’t be seen via iostat(1) (the disks).

语言相关

C标准n1570,关于typedef的一个例子:

6.7.8, 例子: typedef int MILES, KLICKSP(); 这个声明只后:
MILES distance; 这个distance是一个int类型的变量;
extern KLICKSP *metricp; metricp是一个指向无参数并且返回int的函数的指针; 这个指针的定义就是和正常的思维/逻辑有点冲突。

按照第一个int类型的同义词的定义个数,前面是要被替换的类型,后面是重新定义的一个类型别名。
跟着第一个例子的逻辑,第二个 typedef int funcp(); 这个格式就很难理解。
相似的:typedef char char40[40];这里的也很难理解,谁能一下子理解char40是一个 char类型的一个一维数组,40个元素。

https://stackoverflow.com/questions/4523497/typedef-fixed-length-array

[root@10 test]# cat typedef.c
#include <stdio.h>

typedef int a();
a *b;
typedef char a40[40];
a40 c;

int process(a40 a)
{
    
    
        printf("address of a = 0x%x, a=0x%x\n", &a, a);
        return 0;
}
int main()
{
    
    
        a40 e;
        printf("address of e = 0x%x, e=0x%x\n", &e,e);
        process(e);
        return 1;
}
[root@10 test]# ./a.out
address of e = 0x1805a4c0, e=0x1805a4c0
address of a = 0x1805a4a8, a=0x1805a4c0

宏对于魔数的定义

如果使用裸魔数,就是一个所见即所得的例子。但是不利于维护,需要多走一步有利于代码的维护。

猜你喜欢

转载自blog.csdn.net/qq_36428903/article/details/125365261