2

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?

Govind Parmar
  • 20,656
  • 7
  • 53
  • 85
C.J.
  • 15,637
  • 9
  • 61
  • 77

2 Answers2

4

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.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • `execl`, surely. Anyway, that brings up the other problem - execl only can work that way because _all_ of its arguments [including NULL] are the same type: `char *`. This question's `end` can only work if it is the same type as the other arguments that his function are expecting. – Random832 Apr 21 '11 at 17:05
  • And it's not: 'end' in my code is just at the end of a long user defined enumeration list. So it's not anywhere near being a char*. – C.J. Apr 21 '11 at 17:06
4

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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278