lkml.org 
[lkml]   [1997]   [Jan]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: 2.1.22 unneeded global symbols
Date
From
Alan Cox wrote:

>> If you want to pass a pointer to a variable to somewhere else, it doesn't
>> have to be extern; it can be made static.
>
>Mnay of the network pointers are passed from other files in the network
>code.

\begin{C-Legalese}
If you pass the address of object to another compilation unit
(i.e. source file), this object does not need to be extern; it
can be static or allocated (but NOT automatic).
\end{C-legalese}

We're probably not discussing the same subject, or else I'm not getting
through.

Let's take another example, which is also perfectly valid C:

hello.h:

char *hello_fcn(void);

hello.c:

#include "hello.h"

static char msg[]="Hello, world!\n";

char *hello_fcn(void)
{
return msg;
}

main.c:

#include <stdio.h>

#include "hello.h"

int main()
{
char *mymsg;

msg = hello_fcn();
printf("%s",mymsg);
return 0;
}

In this example, msg does not have to be extern; static is fine.
--
Thomas Koenig, Thomas.Koenig@ciw.uni-karlsruhe.de, ig25@dkauni2.bitnet.
The joy of engineering is to find a straight line on a double
logarithmic diagram.

\
 
 \ /
  Last update: 2005-03-22 13:38    [W:0.052 / U:0.572 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site