【发布时间】:2015-08-06 01:16:03
【问题描述】:
我正在为我的 DES 算法使用结构:
typedef struct {
int size;
int capacity;
unsigned char *block;
}Blocks64;
我已经对它做了很多事情,所以我有一些关于 unsigned char 的信息。我在一个我称之为迭代的函数中,我需要通过参数发送它,所以我可以在函数中修改它并且更改保留在结构上,所以据我所知,这是这样做的方法:
void iterations(Block64 *blocks){
printf("This is the first char: %c",get_64bBlocks_char(&blocks,0,0));
}
在方法内部,我有一个printf();,所以我可以检查它是否与我发送的那个相同......但它不是。在我调用迭代的函数上,我有相同的代码:
printf("This is the first char: %c",get_64bBlocks_char(&blocks,0,0));
它会打印我存储在其中的内容,但在迭代方法中却不是。
所以只是测试,我这样做了:
void iterations(Block64 blocks){
printf("This is the first char: %c",get_64bBlocks_char(&blocks,0,0));
}
现在我可以正确接收它了!如果我在迭代方法内部进行更改,它会影响方法之外的那个。我真的不明白!据我所知,我必须使用指向该结构的指针,以便可以通过引用传递它。我现在的编译器是 Visual Studio 2015。
【问题讨论】:
-
打开警告级别。两者之一不应该干净地编译。
标签: c visual-studio data-structures parameter-passing pass-by-reference