473,811 Members | 3,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1461
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.c omwrote:
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.c omwrote:
>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
compatibilit y 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.c omwrote:
>>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
compatibili ty 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.l earn.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******** *************** ***********@i72 g2000hsd.google groups.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
2805
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 _build_used(): .... y = x + 1 .... return x, y ....
9
3701
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 discuss how reflection does this, but I cannot find the syntax to do this. I have tried several code example off of gotdotnet and other articles. Can somebody please show me the code to do this?
3
14963
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) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
8
4835
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
1756
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 didn't make some fundamental mistake somewhere. void swapArgs( int &parm1, int &parm2 ); void swapArgs( int &parm1, int &parm2 ) { int zoot;
4
6186
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 returns false.?
5
1384
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
2070
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 alias = Test.F.FF.FFF.FFFF;
28
4345
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
2495
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 the process the object will be properly destroyed: Set Object1 = Nothing
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10393
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.