相关疑难解决方法(0)

char s []和char*s有什么区别?

在C中,可以在声明中使用字符串文字,如下所示:

char s[] = "hello";
Run Code Online (Sandbox Code Playgroud)

或者像这样:

char *s = "hello";
Run Code Online (Sandbox Code Playgroud)

那么区别是什么呢?我想知道在编译和运行时的存储持续时间实际发生了什么.

c string constants char

495
推荐指数
6
解决办法
33万
查看次数

在C中的struct指针之间转换

请考虑以下代码.

typedef struct{
    int field_1;
    int field_2;
    int field_3;
    int field_4;

    uint8_t* data;
    uint32_t data_size;
} my_struct;

void ext_function(inalterable_my_struct* ims, ...);
Run Code Online (Sandbox Code Playgroud)

我想允许ext_function(由第三方书面)仅修改field_3field_4my_struct.所以我做了以下事情:

typedef struct{
    const int field_1;
    const int field_2;
    int field_3;
    int field_4;

    const uint8_t* data;
    const uint32_t data_size;
} inalterable_my_struct;

void ext_function(inalterable_my_struct* ims, ...);
Run Code Online (Sandbox Code Playgroud)

在调用之间my_structinalterable_my_struct之前转换指针是否安全ext_function(如下所示)?

void call_ext_function(my_struct* ms){
    inalterable_my_struct* ims = (inalterable_my_struct*)ms;
    ext_function(ims, ...);
}
Run Code Online (Sandbox Code Playgroud)

c casting

15
推荐指数
1
解决办法
1112
查看次数

如何在C源代码中存储段落?

我是一名perl程序员并且惊讶地发现c语言没有方便的方式存储段落,例如:

       my $a = <<'dd';
          hello wolrd..
           1
            2
             3
       dd 
Run Code Online (Sandbox Code Playgroud)

那我怎么在C中进行smiliary操作呢?

c perl

2
推荐指数
2
解决办法
762
查看次数

标签 统计

c ×3

casting ×1

char ×1

constants ×1

perl ×1

string ×1