我创建了一些简单的代码来测试将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) 我有一种情况,我有一个结构,我希望能够在其他模块中本地声明它,但我只希望定义结构的模块能够实际访问成员。请注意,这是针对嵌入式应用程序的,因此我无法动态分配内存 (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 指针并将它分配在 …
对于 BLE 广告类型 LOCAL_NAME_COMPLETE,是否有最小长度要求?
我在规范中找不到任何长度规范(除了它需要适合 31 字节的广告数据包减去广告数据包中已有的任何其他内容),但我遇到了一个似乎存在的问题。我想在这里确认一下。