对于我正在处理的项目,最好有一个通用的“函数指针”类型。但是,在 C 中,要拥有指向函数的指针,您需要在函数指针的类型中指定原型。
例如,如果我有 function void setdata(short data),我不能将它存储在与 function 相同的指针中int getdata(),因为它们的参数和返回值是不同的。
经过一些横向思考,我想出了以下解决方法:
typedef long (* PFL)(); /* pointer to function that returns a long... */
typedef short (* PFI)(); /* pointer to function that returns a short... */
typedef void (* PFV)(); /* pointer to function that returns a void... */
typedef void (* PFVAL)(long); /* pointer to function that returns a void...
but has a long argument...*/
typedef void (* PFVAI)(short); /* pointer to function that …Run Code Online (Sandbox Code Playgroud) 我误读了gzip文档,现在我必须从许多目录中删除大量的".gz"文件.我尝试使用'find'来查找所有.gz文件.但是,只要名称中有空格的文件,rm就会将其解释为另一个文件.只要有破折号,rm就会将其解释为新旗帜.我决定用'sed'用"\"代替空格,用空格破坏用"\ - "代替,这就是我想出来的.
find . -type f -name '*.gz' | sed -r 's/\ /\\ /g' | sed -r 's/\ -/ \\-/g'
Run Code Online (Sandbox Code Playgroud)
当我在一个文件上运行find/sed查询时,例如,其名称为"Test - File - for - show.gz",我得到了输出
./Test\ \-\ File\ \-\ for\ \-\ show.gz
Run Code Online (Sandbox Code Playgroud)
这对于rm来说似乎是可以接受的,但是当我跑步时
rm $(find . -type f -name '*.gz'...)
Run Code Online (Sandbox Code Playgroud)
我明白了
rm: cannot remove './Test\\': No such file or directory
rm: cannot remove '\\-\\': No such file or directory
rm: cannot remove 'File\\': No such file or directory
rm: cannot remove '\\-\\': No such file or directory …Run Code Online (Sandbox Code Playgroud) 对于大多数 C 编译器,可以在结构上指定编译器属性,该属性定义该结构的成员在内存中的对齐方式。前任:
typedef struct{
char a;
char b;
} __attribute__((aligned(2))) TwoChars;
Run Code Online (Sandbox Code Playgroud)
如果char a以地址 0xA 结束(为简单起见),则char b不会在地址 0xB 处,而是在 0xC 处,因为它与 2 个字节对齐。
我的问题是:这个属性是由结构成员继承的吗?前任:
typedef struct{
char a;
char b;
} TwoChars;
typedef struct {
TwoChars tc;
char c;
} __attribute__((aligned(1))) ThreeChars;
Run Code Online (Sandbox Code Playgroud)
这在内存中最终会是什么样子?怎么样} __attribute__((aligned(2))) TwoChars?