Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

extern keyword givving error in keil

Status
Not open for further replies.

embpic

Advanced Member level 3
Joined
May 29, 2013
Messages
742
Helped
80
Reputation
160
Reaction score
77
Trophy points
1,308
Location
india
Activity points
5,213
Hello master's
i am using keil and p89v51rd2 controller whenever i used Extern as datatype it giving error .
is there any solution
thanx..
 

Can you post your code (the relevant part) and the error you get?
 

variable i declare as extern it gives me warnings sorry error is not given.
but when i used as xdata or without any thing it gives me 0error and 0warnings
Code:
extern unsigned char k1,i;
xdata unsigned char read_data[7]={0};


HTML:
Build target 'Target 1'
compiling main.c...
linking...
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  K1
    MODULE:  main.obj (MAIN)
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  I
    MODULE:  main.obj (MAIN)
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  K1
    MODULE:  main.obj (MAIN)
    ADDRESS: 016BH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  I
    MODULE:  main.obj (MAIN)
    ADDRESS: 016DH
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  K1
    MODULE:  main.obj (MAIN)
    ADDRESS: 0171H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  I
    MODULE:  main.obj (MAIN)
    ADDRESS: 0192H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  I
    MODULE:  main.obj (MAIN)
    ADDRESS: 0194H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  I
    MODULE:  main.obj (MAIN)
    ADDRESS: 0236H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  I
    MODULE:  main.obj (MAIN)
    ADDRESS: 0255H
*** WARNING L2: REFERENCE MADE TO UNRESOLVED EXTERNAL
    SYMBOL:  I
    MODULE:  main.obj (MAIN)
    ADDRESS: 0257H
Program Size: data=12.3 xdata=35 code=905
creating hex file from "test"...
"test" - 0 Error(s), 10 Warning(s).
 

did you add the file(the variable where declared originally) to the project, and also verify that the original variable is global....
 

yes, you will need to add the file where this variable is actually defined.
Extern is a pure declaration without any definition, and is normally used to import any variable from different files when using multifile compilation.
 

@Venkadesh_M yes i have add the file and declare it in header.h file i am posting full project here.
i am using keil compiler and and p89v51rd2

- - - Updated - - -

declare any variable as extern it will give an error.
 

Attachments

  • Test_Program.rar
    46 KB · Views: 84

@Venkadesh_M yes i have add the file and declare it in header.h file i am posting full project here.
i am using keil compiler and and p89v51rd2

- - - Updated - - -

declare any variable as extern it will give an error.

there is no header.h in project file........
Best practice is declaring it in a c file and using extern in another c file....
 

sorry i meant to say i have declare variables in .h that is header file u can use any variable and use as extern and see result. it gives warnings. and due to not use of extern i need to initaite variable to zero.

thanx...

- - - Updated - - -

and again some memory get waste that code memory increase.
 

that is static data type(automatically initialized and holds the data outside the function also)... the extern type is not specifying the storage location it means the variable is in different c file....
 

i am not getting what u meant to say.
 


Code C - [expand]
1
static int c;


when declaring a variable in static data type Its scope will be inside the function only but It will be automatically initialized in the first time function call and will remain the last value in next function call (like a global variable but the scope is inside a function only)...


Code C - [expand]
1
extern int c;


You can not do this without the variable c globally declared in other c file added with in your project....
It is just to mention that the c is global to this file also...

And a good c program doesnt compiles with any errors as well as any warnings....
 

yes u are right and i am declaring variable as extern unsigned char k,i; even though it is giving error. here i have again have attached my project with is post. and i have changed file named as i2c.h

- - - Updated - - -

yes u are right and i am declaring variable as extern unsigned char k,i; even though it is giving error. here i have again have attached my project with is post. and i have changed file named as i2c.h
and u right good programmer doesn't compile with single error and warnings also
 

Attachments

  • Test_program_2.rar
    45.8 KB · Views: 82

Once again don declare a variable in Header file........
If you include the file in more files means they will be crated with its name in all files..........
Here am attaching the example pro for extern variable.....
 

Attachments

  • dev c.7z
    186.6 KB · Views: 89
Last edited:

ok sir but i tried that one also, still not working i tried to declare the variable in main.c file also and even where i have used variables there also. but still same error.
sir plz show it in my example.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top