English 中文(简体)
结构结构的通过
原标题:Passing structure with list of structures to function
  • 时间:2012-04-24 12:52:36
  •  标签:
  • c

我有原型的功能:

void procedureForEachWave(struct barge *Barge, struct settings *Settings, struct wave *Wave)

在另一项职能中,我还有一个称为“<条形状><>>>>>><>代码/代码”的结构,我利用这一结构将信息发送到几个星上运行的职能中,而这一结构的一个要素是<条码>清单,因此该代码的简短切入:

struct threadData data;
data.waveList = (struct wave*) malloc(sizeof(struct wave)*nrOfWaves);

我在另一个职能中利用这一职能,我基本首先向结构数据发出一个点,然后在这项职能中,“procedure forEachWav”职能被呼吁发挥类似的作用:

procedureForEachWave(data->Barge, data->Settings, &data->waveList[i]);

This works fine. However, I also want to do an analysis where I only use one wave, meaning that the list only contains one element, and I therefore don t need to call the first function. I only want to do this:

procedureForEachWave(Barge, Settings, &data.waveList[0]);

但这并不可行。 为什么? 以及我如何工作? 为了澄清,现在数据被宣布为变数,而不是点数,而Barge和环境已经是点数。 波列主义者也这样说:

data.waveList = (struct wave*) malloc(sizeof(struct wave));
问题回答

如果不知道在<代码>procedureForEachWave内发生什么,很难(如果不是不可能)说明问题是什么。

然而,它的确像“条形”数据>,正在不同地将“条形”与“t”不同。 如果它们使用相同的“>数据编号>/编号”,则该词应当相同(替代“编号0>i>>。 如果情况不同,请提供这一条其他术语的定义:

2. 审议法典的碎片:

extern void wave_function(struct wave *);
struct wave value     =   { ... };
struct wave array[10] = { { ... } };

wave_function(&value);
wave_function(array);
wave_function(&array[5]);

所谓功能不能从被赋予的指点人中看出,它是否被传达到单一价值,还是成为一系列价值观的指点。 电话职能和所谓的功能必须商定如何使用点人,或许可将阵列中的内容数目作为单独的理由:

extern void alt_wave_function(struct wave *, size_t);

alt_wave_function(&value, 1);
alt_wave_function(array, 10);
alt_wave_function(&array[5], 3);

注意,如果大小与点人(www.rocp>&)相传,那么“>值/编号”的大小就超过1,你就会变成不明确的行为。 其余两条电话是完全合理的:第三条电话是有效通过三个阵列组成的。

因此,在一项职能范围内,任何点理由都可以作为单一价值的点子,或作为一系列价值观中第一个项目的点子。 两者都是正确的。 事实上,你甚至可以写:

void wave_function(struct wave *ptr)
{
}

void wave_function(struct wave ptr[])
{
}

这些是等同的声明(但只是在论点清单中)。 你甚至可以包括阵列的大小,但除非你在C99 syntax上穿着:

void wave_function(struct wave array[static 4])
{
}

这一通知意味着,打电话者必须保证,在座标上传到这个版本的<条码>wave_的阵列中至少有4项内容。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签