小编rye*_*ger的帖子

在C++中将〜0u赋值给变量是什么意思?

我理解的0u意思是0无符号,但~开头是什么意思?在这种情况下它是表示反转还是其他意思?

c++

28
推荐指数
3
解决办法
3万
查看次数

为什么将一个char数组转换为int指针并使用指针写入它使数据反转?

我创建了一些简单的代码来测试将char数组转换为int指针.这正如我预期的那样工作正常,但是当我使用指针写入数组时,当我打印出c数组时,数据交换了MSB < - > LSB.为什么会这样?这是操作系统依赖的吗?

#include "stdio.h"

const int SIZE = 12;

int _tmain(int argc, _TCHAR * argv[]) {
    unsigned char c[SIZE] = {
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
    };
    unsigned int * ptr = (unsigned int * ) c;
    int i;

    printf("Int size=%d\n", sizeof(unsigned long));

    for (i = 0; i < sizeof(c); i++) {
        printf("%X, ", c[i]);
    }
    printf("\n\n");

    for (i = 0; i < sizeof(c) / sizeof(unsigned long); i++) { * …
Run Code Online (Sandbox Code Playgroud)

c c++ arrays pointers

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

将 typedef struct 设为 public 以用于本地声明,但将结构成员访问权限保留给它在其中定义的模块

我有一种情况,我有一个结构,我希望能够在其他模块中本地声明它,但我只希望定义结构的模块能够实际访问成员。请注意,这是针对嵌入式应用程序的,因此我无法动态分配内存 (malloc)。

foo.h

typedef struct my_struct T_my_struct;

int GetA(T_my_struct *bar);
int GetB(T_my_struct *bar);
Run Code Online (Sandbox Code Playgroud)

foo.c

#include "foo.h"

struct my_struct
{
    int a;
    char b;
}

int GetA(T_my_struct *bar)
{
    return bar->a;
}

int GetB(T_my_struct *bar)
{
    return bar->b;
}

void Init(T_my_struct *bar)
{
    bar->a = 5;
    bar->b = 3;
}
Run Code Online (Sandbox Code Playgroud)

酒吧.c:

#include "bar.h"
#include "foo.h"
#include <stdio.h>
#include <stdlib.h>

static T_my_struct local_instance;  // <--storage size of local_instance not know here

int main()
{
    Init(&local_instance);

    printf("A: %d\n", GetA(&local_instance));
}
Run Code Online (Sandbox Code Playgroud)

我知道我可以创建一个本地 T_my_struct 指针并将它分配在 …

c embedded struct typedef

5
推荐指数
1
解决办法
753
查看次数

BLE 4.0 广告本地名称完整是否有最小设备名称长度?

对于 BLE 广告类型 LOCAL_NAME_COMPLETE,是否有最小长度要求?

我在规范中找不到任何长度规范(除了它需要适合 31 字节的广告数据包减去广告数据包中已有的任何其他内容),但我遇到了一个似乎存在的问题。我想在这里确认一下。

bluetooth bluetooth-lowenergy

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

标签 统计

c ×2

c++ ×2

arrays ×1

bluetooth ×1

bluetooth-lowenergy ×1

embedded ×1

pointers ×1

struct ×1

typedef ×1