@jalaj  guys please understand how the static and extern work first.

static makes the variables or functions defined in an object file to be
local to that object file.
When you declare the variable or function  as extern , it means that
definition is present in some other object file and it will be resolved at
the link time only.
By default all the global variables and functions are visible to other
object files.

Example:

a.c
===

int var = 10;   // global variable so accessible to other files.

static void func()  // static - so not accessible to other files
{

}


b.c
===

extern int var ;

main()
{

     var = 20 ;

      func() ;  // this is not permitted since the func() is declared as
static

}



This is how the compilation works:

gcc -c -o a.o  a.c
gcc  -c -o b.o  b.c


gcc   -o  exe  b.o  a.o
// This will lead to linker error since func is declared static.


Regards
Arul

On Fri, Feb 25, 2011 at 12:00 AM, nishaanth <nishaant...@gmail.com> wrote:

> Declare it as *static.*
>
>
> On Wed, Feb 23, 2011 at 11:33 PM, Jammy <xujiayiy...@gmail.com> wrote:
>
>> Are you talking about IPC?
>>
>> On Feb 22, 10:05 am, jaladhi dave <jaladhi.k.d...@gmail.com> wrote:
>> > What do you mean by data element here ? Also by file you mean the file
>> where
>> > you wrote the code ? And above all which programming language are we
>> talking
>> > ?
>> >
>> > You hit send button too early I  guess :)
>> >
>> > On 22-Feb-2011 7:39 PM, "jalaj jaiswal" <jalaj.jaiswa...@gmail.com>
>> wrote:
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > > Is there any way by which a data element in a file is accessible by
>> > another
>> > > file, where the program has multiple files. That data element should
>> be
>> > > accessible to a particular file only and inaccessible to the rest.?
>> >
>> > > declaring it as an extern will make it accessible to all i think ..
>> what
>> > cud
>> > > be the answer ?
>> >
>> > > --
>> > > With Regards,
>> > > *Jalaj Jaiswal* (+919019947895)
>> > > Software developer, Cisco Systems
>> > > B.Tech IIIT ALLAHABAD
>> >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> Groups
>> >
>> > "Algorithm Geeks" group.> To post to this group, send email to
>> algogeeks@googlegroups.com.
>> > > To unsubscribe from this group, send email to
>> >
>> > algogeeks+unsubscr...@googlegroups.com.> For more options, visit this
>> group at
>> >
>> > http://groups.google.com/group/algogeeks?hl=en.
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> S.Nishaanth,
> Computer Science and engineering,
> IIT Madras.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to