Callling a function from another file...

D

David Thompson

You have to define the function the same way you declared it
though; e.g. you can't have a prototype declaration and a
K&R style definition. (The compiler is not required to
diagnose this either, you just get weird runtime behaviour).
Not quite. You can 'cross' these if (and only if) the prototype form
matches _the result of applying default argument promotions to_ the
nonprototype form. This is tricky and system-dependent enough that the
PP is unlikely to get it right, and the people who know enough to get
it right are unlikely to want to do it. About the only case I would
approve of would be where you have to interface to legacy code that
you literally can't change _at all_ not even 'syntax cleanup'. There
is never a technical need for this, but there can be legal ones.

And yes if you do get it wrong it's UB. Although in a number of simple
cases it accidentally works, because it is fairly common for calling
conventions to promote everything to at least a (machine dependent)
'word' and this often just happens to do the same thing the default
promotions do. The Standard default promotions, of course, are partly
based on what the PDP-11 convention actually did.

- formerly david.thompson1 || achar(64) || worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top