在Linux内核代码中,我发现了以下无法理解的内容.
struct bts_action {
u16 type;
u16 size;
u8 data[0];
} __attribute__ ((packed));
Run Code Online (Sandbox Code Playgroud)
代码在这里:http://lxr.free-electrons.com/source/include/linux/ti_wilink_st.h
零元素数据数组的需求和目的是什么?
我只是在读书
ISO/IEC 9899:201x委员会草案 - 2011年4月12日
我在5.1.2.2.3程序终止下找到了
..reaching the } that terminates the main function returns a value of 0.
Run Code Online (Sandbox Code Playgroud)
这意味着如果你没有指定任何return语句main()
,并且如果程序成功运行,那么在main的右括号中将返回0.
但是在下面的代码中我没有指定任何return语句,但它不返回0
#include<stdio.h>
int sum(int a,int b)
{
return (a + b);
}
int main()
{
int a=10;
int b=5;
int ans;
ans=sum(a,b);
printf("sum is %d",ans);
}
Run Code Online (Sandbox Code Playgroud)
编
gcc test.c
./a.out
sum is 15
echo $?
9 // here it should be 0 but it shows 9 why?
Run Code Online (Sandbox Code Playgroud) static struct fuse_oprations hello_oper = {
.getattr = hello_getattr,
.readdir = hello_readdir,
.open = hello_open,
.read = hello_read,
};
Run Code Online (Sandbox Code Playgroud)
我不太了解这个C语法.我甚至无法搜索,因为我不知道语法的名称.那是什么?
我想编写一个检查目录是否存在的程序; 如果该目录不存在,那么它会在其中创建目录和日志文件,但如果该目录已经存在,那么它只是在该文件夹中创建一个新的日志文件.
我将如何在C中使用Linux执行此操作?
在Linux内核源代码中我找到了这个函数:
static int __init clk_disable_unused(void)
{
// some code
}
Run Code Online (Sandbox Code Playgroud)
在这里,我无法理解它__init
意味着什么.
也许从平台到平台不同,但是
当我使用gcc编译并运行下面的代码时,我每次都在ubuntu 11.10中得到0.
#include <stdio.h>
#include <stdlib.h>
int main()
{
double *a = (double*) malloc(sizeof(double)*100)
printf("%f", *a);
}
Run Code Online (Sandbox Code Playgroud)
为什么malloc表现得像这样,即使有calloc?
是不是意味着只是将值初始化为0会产生不必要的性能开销,即使您有时不想要它也是如此?
编辑:哦,我之前的例子不是initiazling,但碰巧使用"新鲜"块.
我正在寻找的是为什么它在分配一个大块时初始化它:
int main()
{
int *a = (int*) malloc(sizeof(int)*200000);
a[10] = 3;
printf("%d", *(a+10));
free(a);
a = (double*) malloc(sizeof(double)*200000);
printf("%d", *(a+10));
}
OUTPUT: 3
0 (initialized)
Run Code Online (Sandbox Code Playgroud)
但感谢您指出在进行mallocing时存在安全原因!(没想过).当分配新块或大块时,它必须初始化为零.
在C程序中,如果我们想从终端提供一些输入,那么我们可以通过以下方式给出:
int main(int argc, char *argv[])
Run Code Online (Sandbox Code Playgroud)
同样,如果我们想获得main()
函数的返回值,那么我们如何才能得到它?
在每个main()
我们写return 1
或return 0
; 我怎么知道我main()
在码头回来了什么?
编辑:1
我得到它,因为echo $?
我们可以获得返回值,main()
但它只允许我成功返回小于125(在Linux中)的值.不止于此返回值不能被成功地接收到$ variable
这样
为什么int
回归类型main()
?为什么不保留它short int
?
EDIT2
如果main()
返回大于125的值,我在哪里可以找到错误代码的含义?
我无法在Linux中找到conio.h的等效头文件.
在Linux中有getch()
&getche()
function功能吗?
我想制作一个开关盒基本菜单,用户只需按一个键即可提供选项,并且应该向前移动过程.按下他的选择后,我不想让用户按ENTER键.
我经常发现一些URL如下所示:
www.something.com/some_page/#someword
Run Code Online (Sandbox Code Playgroud)
在写完这个页面后,some_page将会打开然后滚动设置,这样我就可以在屏幕的开头看到" someword ".
我不知道"#"是什么意思.一旦我 使用任何网址制作#someotherword它有时会工作,有时它不会.
我没有得到URL中的#.它是任何语言或网址的任何功能或其他东西?
编辑:有可能你认为我的问题是新的,但我不是网络设计技术,我只是对此感到好奇.
编辑:我不是某个网站的所有者,但是当我关注某个网页的某个特定部分时,我怎么能用#给网址并将该网址提供给另一个?
我关注我的个人资料中的答案部分,然后我将准备下面的URL并将其提供给某人.
这有效,但有一段时间没有.
这不起作用.
我只是一个用户,我不想知道网站是用哪种语言构建的.
int a = 10;
switch(a){
case 0:
printf("case 0");
break;
case 1:
printf("case 1");
break;
}
Run Code Online (Sandbox Code Playgroud)
以上代码有效吗?
如果我确定int a
不会有除1和0之外的任何其他值,我可以避免default
吗?
如果在任何情况下一个值与1和0不同怎么办?
我知道这是一个愚蠢的问题,但我在想,也许这将是非法的或未定义的行为,所以我只是要求确认.