473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Diagnostic required for missing function definition?

Does the following program require a diagnostic? Which section
of the Standard deals with this? (I read the section on function
calls and didn't see anything).

void f(void);

int main(void) { f(); }

Is the answer still the same if the function declaration was:
static void f(void);

Mar 1 '07 #1
11 2491
Old Wolf said:
Does the following program require a diagnostic? Which section
of the Standard deals with this? (I read the section on function
calls and didn't see anything).

void f(void);

int main(void) { f(); }
No diagnostic message is required. For all the compiler knows, the
definition of f() is in another translation unit. But if it isn't,
you'll get a linker error, obviously.
Is the answer still the same if the function declaration was:
static void f(void);
Excellent question. As far as I can tell, there is still no requirement
for a diagnostic message (although of course the implementation is free
to provide one if it feels like so doing), but I could easily be wrong.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 1 '07 #2
In article <Yv*********************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>Old Wolf said:
>Does the following program require a diagnostic? Which section
of the Standard deals with this? (I read the section on function
calls and didn't see anything).

void f(void);

int main(void) { f(); }

No diagnostic message is required. For all the compiler knows, the
definition of f() is in another translation unit. But if it isn't,
you'll get a linker error, obviously.
Isn't the linker part of the implementation? So if a linker error
is required, that would mean the implementation as a whole must issue
a diagnostic.

N869 6.9 says:
[#5] An external definition is an external declaration that
is also a definition of a function or an object. If an
identifier declared with external linkage is used in an
expression (other than as part of the operand of a sizeof
operator), somewhere in the entire program there shall be
exactly one external definition for the identifier;
otherwise, there shall be no more than one.127)

This is *not* in a Constraints section, so it looks to me like it's
undefined behavior and the implementation (linker in this case) is allowed
to silently accept it or silently refuse to generate an executable.

(This seems reasonable to me. Consider this source file representing
a complete program:
--------
void read(void);
int main(void) { read(); return 0; }
--------
I would be surprised to find a Unix-hosted C implementation that fails
to compile this, but the executable may or may not behave sensibly.)

>Is the answer still the same if the function declaration was:
static void f(void);

Excellent question. As far as I can tell, there is still no requirement
for a diagnostic message (although of course the implementation is free
to provide one if it feels like so doing), but I could easily be wrong.
N869 6.9#3 (which *is* in a Constraints section) says:
Moreover, if an identifier declared with
internal linkage is used in an expression (other than as a
part of the operand of a sizeof operator), there shall be
exactly one external definition for the identifier in the
translation unit.

I don't think just a prototype is an "external definition" as defined
in #5, so it looks to me like using a function (or other object) that is
declared static and not defined in that translation unit is a constraint
violation.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca

Odd, that. My programs don't tend to make my computer systems fall over.
--Richard Heathfield in comp.lang.c
Mar 1 '07 #3
Old Wolf a écrit :
Does the following program require a diagnostic? Which section
of the Standard deals with this? (I read the section on function
calls and didn't see anything).

void f(void);

int main(void) { f(); }

Is the answer still the same if the function declaration was:
static void f(void);
No diagnostic is required, as far as I see

main() has an implicit result (zero) so the absence of an explicit
result is OK.
Mar 1 '07 #4
Dave Vandervies said:
In article <Yv*********************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>>Old Wolf said:
>>Does the following program require a diagnostic? Which section
of the Standard deals with this? (I read the section on function
calls and didn't see anything).

void f(void);

int main(void) { f(); }

No diagnostic message is required. For all the compiler knows, the
definition of f() is in another translation unit. But if it isn't,
you'll get a linker error, obviously.

Isn't the linker part of the implementation?
Yes - although it needn't be an integral part.
So if a linker error
is required, that would mean the implementation as a whole must issue
a diagnostic.
At the point where it realises the reference cannot be resolved, yes.
But need that point be reached? I'm vaguely thinking of a system where
function calls are bound at runtime - DLLs and the like.
N869 6.9 says:
[#5] An external definition is an external declaration that
is also a definition of a function or an object. If an
identifier declared with external linkage is used in an
expression (other than as part of the operand of a sizeof
operator), somewhere in the entire program there shall be
exactly one external definition for the identifier;
otherwise, there shall be no more than one.127)

This is *not* in a Constraints section, so it looks to me like it's
undefined behavior and the implementation (linker in this case) is
allowed to silently accept it or silently refuse to generate an
executable.
I'll buy that.

<snip>

[static equivalent]
N869 6.9#3 (which *is* in a Constraints section) says:
Moreover, if an identifier declared with
internal linkage is used in an expression (other than as a
part of the operand of a sizeof operator), there shall be
exactly one external definition for the identifier in the
translation unit.

I don't think just a prototype is an "external definition" as defined
in #5, so it looks to me like using a function (or other object) that
is declared static and not defined in that translation unit is a
constraint violation.
You know your trouble, Dave? You're just not lazy enough!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 2 '07 #5
"jacob.navia" <ja***@jacob.remcomp.frwrites:
Old Wolf a écrit :
>Does the following program require a diagnostic? Which section
of the Standard deals with this? (I read the section on function
calls and didn't see anything).
void f(void);
int main(void) { f(); }
Is the answer still the same if the function declaration was:
static void f(void);
No diagnostic is required, as far as I see

main() has an implicit result (zero) so the absence of an explicit
result is OK.
I don't think the lack of a return was the issue. (The rule that
main() implicitly returns 0 is new in C99, but even in C90 falling off
the end of main() doesn' require a diatnostic; it merely returns an
undefined result (that's *not* undefined behavior) to the calling
environment.) The question was about calling a function f() that's
been declared but not defined.

Obviously such calls are legitimate for functions defined in other
translation units in the same program. Whether and when a diagnostic
is required if the function is never defined is another question (one
I'm too lazy to figure out how to answer).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 2 '07 #6
Old Wolf wrote:
>
Does the following program require a diagnostic? Which section
of the Standard deals with this? (I read the section on function
calls and didn't see anything).

void f(void);

int main(void) { f(); }

Is the answer still the same if the function declaration was:
static void f(void);
You don't have a function to call. You declared it, but never
defined it.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Mar 2 '07 #7
In article <45***************@yahoo.com>,
CBFalconer <cb********@maineline.netwrote:
>Old Wolf wrote:
>>
Does the following program require a diagnostic? Which section
of the Standard deals with this? (I read the section on function
calls and didn't see anything).

void f(void);

int main(void) { f(); }

Is the answer still the same if the function declaration was:
static void f(void);

You don't have a function to call. You declared it, but never
defined it.
This just in: Water is wet.

Mar 2 '07 #8
In article <79******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
>Dave Vandervies said:
>So if a linker error
is required, that would mean the implementation as a whole must issue
a diagnostic.

At the point where it realises the reference cannot be resolved, yes.
But need that point be reached? I'm vaguely thinking of a system where
function calls are bound at runtime - DLLs and the like.
I've never encountered a system that did runtime identifier binding
without doing a link-time pass as well to make sure that the identifiers
that were needed could be found. Of course if you try to run it
with something other than the runtime linking files that it did that
check against, it could still die with a runtime failure to do the
actual binding.

Finding a suitably named identifier somewhere else, and silently
producing unpredictable results, is also perfectly valid, at least if
I'm correct that using an identifier that you don't provide a definition
for somewhere invokes undefined behavior. This could also be caused by
shuffling dynamically linked objects around behind the implementation's
back (which is actually quite likely to be useful when done by somebody
who understands what they're getting themselves into).

>You know your trouble, Dave? You're just not lazy enough!
No, the real trouble is that I can't figure out how to control under
which conditions I'm lazy enough. Especially since I usually seem to be
a lot more interested in things that are only relevant to other peoples'
questions than things I'm likely to need to know.
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
>Void pointers will automatically be converted to the right type when the
assignment is made. --Simon Biber and
Or to the wrong type, as the case may be. Kaz Kylheku in CLC
Mar 6 '07 #9
In article <es**********@rumours.uwaterloo.cadj******@caffeine.csclub.uwaterloo.ca (Dave Vandervies) writes:
....
I've never encountered a system that did runtime identifier binding
without doing a link-time pass as well to make sure that the identifiers
that were needed could be found.
Well, I have encountered such a system.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Mar 6 '07 #10
In article <JE********@cwi.nl>, Dik T. Winter <Di********@cwi.nlwrote:
>In article <es**********@rumours.uwaterloo.cadj******@caffeine.csclub.uwaterloo.ca (Dave Vandervies) writes:
...
I've never encountered a system that did runtime identifier binding
without doing a link-time pass as well to make sure that the identifiers
that were needed could be found.

Well, I have encountered such a system.
I was fishing for something like that, but more detail would have
been nice.

Which system? To keep it on topic, did the C implementation have anything
interesting about it?
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
Mostly, I plead lack of time. If I had more time I could write
shorter postings...
--Chris Torek in comp.lang.c
Mar 6 '07 #11
In article <es**********@rumours.uwaterloo.cadj******@caffeine.csclub.uwaterloo.ca (Dave Vandervies) writes:
In article <JE********@cwi.nl>, Dik T. Winter <Di********@cwi.nlwrote:
In article <es**********@rumours.uwaterloo.cadj******@caffeine.csclub.uwaterloo.ca (Dave Vandervies) writes:
...
I've never encountered a system that did runtime identifier binding
without doing a link-time pass as well to make sure that the identifiers
that were needed could be found.
Well, I have encountered such a system.

I was fishing for something like that, but more detail would have
been nice.

Which system? To keep it on topic, did the C implementation have anything
interesting about it?
CDC Cyber, NOS/BE, later incarnations. There did exist a C implementation
for it, but I never used that.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Mar 6 '07 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Christopher Benson-Manica | last post by:
Is a conforming C++ implementation required to issue a diagnostic when invoked on the following code? #include <cstdlib> #include <iostream> #include <string> int main() { printf( "Hello,...
13
by: wessoo | last post by:
Hi All. What is The Lvalue Required error message. (What does it mean?Is it an abbreviationof something.) I wrote this test program and I am keeping geting this message. void main() {...
0
by: ViRi | last post by:
There was an error loading types from assembly 'path to the dll 'Missing definition for required runtime implemented delegate method.' I get this error message when trying to add a custom control...
0
by: Jigar.Patel | last post by:
I have simple remoting server exposing following simple method. When I try to add webreference to this server in another project, it gives me following error: Custom tool error: Unable to import...
3
by: CindyRob | last post by:
I am using .NET framework 1.1 SP1, .NET framework SDK 1.1 SP1, with hotfix 82202, Visual studio .NET 2003 with hotfix 823639. I have generated a proxy class using wsdl.exe from a schema that has an...
12
by: spibou | last post by:
I have two identical files , u1.c and u2.c which only contain the line typedef int Q ; When I issue "splint u1.c u2.c" I get u2.c:1:13: Datatype Q defined more than once A function or variable...
8
by: Man with Oscilloscope | last post by:
goto jumping over vla -- diagnostic required? This is a question about C99, 6.8.6.1, example 2 (see test below). I'm currently working on updating an older compiler up to C99. The standard is...
3
by: Joseph Geretz | last post by:
System.InvalidOperationException: WebServiceBindingAttribute is required on proxy classes. My environment: Visual Studio 2005, targeting FX 2.0; I've developed a Web Service which uses DIME to...
5
by: santosh | last post by:
We are given the definition of a "diagnostic message" in 3.10 of the Standard. To quote: 3.10 1 diagnostic message message belonging to an implementation-defined subset of the implementation's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.