Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > typedef and static

Reply
Thread Tools

typedef and static

 
 
asit
Guest
Posts: n/a
 
      01-15-2008
#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 ??
 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      01-15-2008
In article <(E-Mail Removed)>,
pete <(E-Mail Removed)> wrote:

>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.

--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
 
Reply With Quote
 
 
 
 
pete
Guest
Posts: n/a
 
      01-15-2008
Walter Roberson wrote:
>
> In article <(E-Mail Removed)>,
> pete <(E-Mail Removed)> wrote:
>
> >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:

> > typedef void show(int,int);
> >
> > int main()
> > {
> > static show myshow;



--
pete
 
Reply With Quote
 
Walter Roberson
Guest
Posts: n/a
 
      01-15-2008
In article <(E-Mail Removed)>,
pete <(E-Mail Removed)> wrote:
>Walter Roberson wrote:
>>
>> In article <(E-Mail Removed)>,
>> pete <(E-Mail Removed)> wrote:


>> >The error was that functions can't have file scope.


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


>> > typedef void show(int,int);
>> >
>> > int main()
>> > {
>> > static show myshow;

>


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. [...]

--
"Any sufficiently advanced bug is indistinguishable from a feature."
-- Rich Kulawiec
 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      01-16-2008
Walter Roberson wrote:
>
> In article <(E-Mail Removed)>,
> pete <(E-Mail Removed)> wrote:
> >Walter Roberson wrote:
> >>
> >> In article <(E-Mail Removed)>,
> >> pete <(E-Mail Removed)> wrote:

>
> >> >The error was that functions can't have file scope.

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

>
> >> > typedef void show(int,int);
> >> >
> >> > int main()
> >> > {
> >> > static show myshow;

> >

>
> 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.

--
pete
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with Static and non-static methods and feilds o_ssie Java 0 04-09-2009 04:38 PM
CRTP-problem: How can the base class typedef a derived class' typedef? oor C++ 0 05-20-2008 12:39 PM
Instantiating a static class( Class with all static members - methods and variables) SaravanaKumar Java 6 10-19-2004 08:20 AM
A question about typedef and classes and templates.. JustSomeGuy C++ 1 09-20-2003 04:33 AM
Why do static and non-static method names collide? =?ISO-8859-1?Q?Thomas_Gagn=E9?= Java 12 07-05-2003 04:59 PM



Advertisments