typedef and static

A

asit

#include <stdio.h>

typedef void show(int,int);

int main()
{
static show myshow;
myshow(1,100);
//disp(1,5);
return 0;
}

static void myshow(x,y)
int x,y;
{
printf("%d %d\n",x,y);
}

Can anyone please explain the error ??
 
W

Walter Roberson

pete said:
The error was that functions can't have file scope.

C89 3.1.2.2 Linkages of Identifiers
[...]

If the declaration of a file scope identifier for an object
or a function contains the storage class specifier static,
the identifier has internal linkage.
 
P

pete

Walter said:
pete said:
The error was that functions can't have file scope.

C89 3.1.2.2 Linkages of Identifiers
[...]

If the declaration of a file scope identifier for an object
or a function contains the storage class specifier static,
the identifier has internal linkage.

Please excuse me.
I misspelled "function scope" very badly,
when refering to this code:
 
W

Walter Roberson

Walter said:
Please excuse me.
I misspelled "function scope" very badly,
when refering to this code:

Well of course functions cannot have function scope.

C89 3.1.2.1 Scope of Identifiers

An identifier is visible (i.e., can be used) only within a region
of program text called its cope. There are four kinds of scopes:
function, file, block, and function prototype. (A function prototype
is a declaration of a function that declares the types of its
parameters.)

A label name is the only kind of identifier that has function
scope. [...]

Every other identifier has scope determined by the placement of
its declaration (in a declarator or type specifier.) If the
declarator or type specifier that declares the identifier appears
outside of any block or list of parameters, the identifier has
file scope, which terminates at the end of the translation unit.
If the declarator or type specifiers that declares the identifier
appears inside a block or within the list of parameter declarations
in a function definition, the identifier has block scope, which
terminates at the } that closes the associated block. [...]
 
P

pete

Walter said:
Walter said:
Well of course functions cannot have function scope.

C89 3.1.2.1 Scope of Identifiers

It seems that I blew it again.

How about this one?
N869
6.7.1 Storage-class specifiers
[#5] The declaration of an identifier for a function that
has block scope shall have no explicit storage-class
specifier other than extern.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top