Pascal and cdecl keyword in C language [closed]

拥有回忆 提交于 2019-12-02 14:01:17

(As already hinted by Bo Persson, this has (probably) to do with the so-called calling convention.

There is a nice explanation in Wikipedia x86 calling conventions.

Short summary: Different languages (resp. the compilers) may have different conventions in which order the arguments of a function are passed (e.g. on stack).

If you want to link object files where code is written in different languages, this can become an issue. Thus, some compilers have extensions to change the calling convention for function calls. (If nothing denoted the native is used, of course.)


Story Teller pointed out that (beside of the calling convention issue) there is something else in your sample code which is really suspicious.

The prototypes conv1() and conv2() in main have unspecified argument lists. This is allowed in C (elaborated e.g. in SO: C: Unspecified number of parameters - void foo()). Unfortunately, it prevents detection of wrong calling.

conv1() and conv2() have two parameters each. However, both are called in main() with one argument. This is undefined behavior.

(Thank you Story Teller to let me recognize this. The calling convention thing let me totally oversee this as well as the hint in Bo Perssons comment.)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!