473,382 Members | 1,425 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,382 software developers and data experts.

function/variable references in c

Hi Everyone,

when a call to a function is done in a file and if the function isn't
defined, compiler just assumes that it would return a int and that the
definition would be available at some other compilation unit which
should be given to the linker to generate the executable file.

However, why doesn't this extend to a global variable which isn't
declared? The compiler gives as error immediately...

Thanks in advance!!!
Jan 5 '08 #1
6 1448
Rahul wrote:
Hi Everyone,

when a call to a function is done in a file and if the function isn't
defined, compiler just assumes that it would return a int and that the
definition would be available at some other compilation unit which
should be given to the linker to generate the executable file.
This is surely not good practice and is maintened for backward
compatibility only.
However, why doesn't this extend to a global variable which isn't
declared? The compiler gives as error immediately...
Better that that than at link time isn't it?
Thanks in advance!!!

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jan 5 '08 #2
On Jan 5, 3:42 pm, jacob navia <ja...@nospam.comwrote:
Rahul wrote:
Hi Everyone,
when a call to a function is done in a file and if the function isn't
defined, compiler just assumes that it would return a int and that the
definition would be available at some other compilation unit which
should be given to the linker to generate the executable file.

This is surely not good practice and is maintened for backward
compatibility only.
Do you mean resolution during link time?
and backward compatibility with what?

Jan 5 '08 #3
Rahul wrote:
On Jan 5, 3:42 pm, jacob navia <ja...@nospam.comwrote:
>Rahul wrote:
>>Hi Everyone,
when a call to a function is done in a file and if the function isn't
defined, compiler just assumes that it would return a int and that the
definition would be available at some other compilation unit which
should be given to the linker to generate the executable file.
This is surely not good practice and is maintened for backward
compatibility only.

Do you mean resolution during link time?
and backward compatibility with what?
I mean
<quote>
when a call to a function is done in a file and if the function isn't
defined, compiler just assumes that it would return a int and that the
definition would be available at some other compilation unit which
should be given to the linker to generate the executable file.
<end quote>

Implicit int is an obsolescent feature.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
Jan 5 '08 #4
jacob navia wrote, On 05/01/08 19:05:
Rahul wrote:
>On Jan 5, 3:42 pm, jacob navia <ja...@nospam.comwrote:
>>Rahul wrote:
Hi Everyone,
when a call to a function is done in a file and if the function isn't
defined, compiler just assumes that it would return a int and that the
definition would be available at some other compilation unit which
should be given to the linker to generate the executable file.
This is surely not good practice and is maintened for backward
compatibility only.

Do you mean resolution during link time?
and backward compatibility with what?

I mean
<quote>
when a call to a function is done in a file and if the function isn't
defined, compiler just assumes that it would return a int and that the
definition would be available at some other compilation unit which
should be given to the linker to generate the executable file.
<end quote>

Implicit int is an obsolescent feature.
In the latest version of the standard it is not obsolescent (which means
that it is still present but may be removed) it is completely gone from
the language. In the previous standards I believe it was included for
backwards compatibility with pre-standard code.
--
Flash Gordon
Jan 6 '08 #5
On Sat, 5 Jan 2008 02:35:41 -0800 (PST), Rahul <sa*****@yahoo.co.in>
wrote in comp.lang.c:
Hi Everyone,

when a call to a function is done in a file and if the function isn't
defined, compiler just assumes that it would return a int and that the
definition would be available at some other compilation unit which
should be given to the linker to generate the executable file.
Actually, that "feature" was removed from the language in the 1999
version, and all later versions of the C standard. So don't write
code like that anymore.
However, why doesn't this extend to a global variable which isn't
declared? The compiler gives as error immediately...
Why should it? The call of functions without a declaration should
never have been in the language in the first place.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Jan 6 '08 #6

"Rahul" <sa*****@yahoo.co.inwrote in message
news:50**********************************@i72g2000 hsd.googlegroups.com...
Hi Everyone,

when a call to a function is done in a file and if the function isn't
defined, compiler just assumes that it would return a int and that the
definition would be available at some other compilation unit which
should be given to the linker to generate the executable file.

However, why doesn't this extend to a global variable which isn't
declared? The compiler gives as error immediately...

Thanks in advance!!!
that error may have crept into the old C because the compiler could do some
sort of
code generation for a function call, but not for variables.

if function f() is not defined (and not declared in its prototype form -
this is important), the
compiler assumes the form "int f()" , which to very likely to be incorrect,
because the actual definition may be
say void f(int,float). The compiler has generated code at the point of call
for a function with "int" return and
no arguments. Whereras the function expects an int and float (maybe on
stack, or in registers), but does not return anything.
A runtime disaster, no doubt but mericifully detected by linker

In contrast, what code can the compiler generate for an undeclared variable
? None, because the compiler not
psychic to know the type of the variable from its usage !





Jan 7 '08 #7

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

Similar topics

8
by: Nick Coghlan | last post by:
Time for another random syntax idea. . . So, I was tinkering in the interactive interpreter, and came up with the following one-size-fits-most default argument hack: Py> x = 1 Py> def...
9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
8
by: Falc2199 | last post by:
Hi, Does anyone know how to make this work? var sectionId = 5; repeat_section_sectionId(); function repeat_section_5(){ alert("firing"); }
9
by: Ook | last post by:
I need a function that swaps arguements. This is my function. It works, after calling swapArgs aa now has 321, and bb has 123. My question - did I do it right? Just because it works doesn't mean I...
4
by: Gerry Abbott | last post by:
Hi All, Im trying to use thie combination but have not had success. Below is the function It tried the following myriskLevel(2,2) myrisklevel(0,0,2) and the ismissing(Three) alwasy...
5
by: Andrew Poulos | last post by:
I tested the JSON parse/to code from json.org and it works but I don't understand how. Could someone explain how something in this format works: (function() {...})(); Andrew Poulos
22
by: Daniel Rucareanu | last post by:
I have the following script: function Test(){} Test.F = function(){} Test.F.FF = function(){} Test.F.FF.FFF = function(){} Test.F.FF.FFF.FFFF = function(){} //var alias = function(){}; var...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
2
by: Ivor Somerset | last post by:
Hello, In my ASP code I sometimes write functions that return an object (generally an XML node). Such a function is invoked this way: Set Object1 = MyFunction(SomeValue) And at the end of...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.