开发者

Does C varargs use a keyword called 'end'?

I have a lot of code that uses C style variable arguments. The code passes in a variable called end at the very end of our variable length function calls. And.... the code also has an enumerator called end. So far they haven't clashed (compiler error says it has an ambiguous definition: It won't tell me where the mysterious second 'end' is defined) until I changed to the VC 10.0 compiler (VS 2010).

So is end some sort of reserved keyword used especially in variable args? I know very little about them. But I've looked at tons of documentation on variable arguments, as well as searching here, and found nothing (which could be a good thing). So I would guess the answer is that 开发者_如何学编程end is not a special word used with varargs. Can I get someone to confirm this?


No -- C doesn't define end as having any special meaning with varargs. When you write a function that takes a variable argument list, it's up to you to decide how to tell it how long of a list has been passed. Some popular ones are that the first argument specifies (at least indirectly) how many more arguments there are, and passing a "sentinel" value (e.g., NULL) after all the others. For a couple of examples, printf does the former, execl the latter.


Once upon a long time ago (7th Edition Unix, for example), there were three external symbols defined: etext, edata and end. These corresponded to the upper address of the code, the initialized data and the heap. It may be that your definition of end is colliding with that, somehow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜