typedef and static

Discussion in 'C Programming' started by asit, Jan 15, 2008.

  1. asit

    asit Guest

    #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 ??
    asit, Jan 15, 2008
    #1
    1. Advertising

  2. In article <>,
    pete <> 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
    Walter Roberson, Jan 15, 2008
    #2
    1. Advertising

  3. asit

    pete Guest

    Walter Roberson wrote:
    >
    > In article <>,
    > pete <> 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
    pete, Jan 15, 2008
    #3
  4. In article <>,
    pete <> wrote:
    >Walter Roberson wrote:
    >>
    >> In article <>,
    >> pete <> 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
    Walter Roberson, Jan 15, 2008
    #4
  5. asit

    pete Guest

    Walter Roberson wrote:
    >
    > In article <>,
    > pete <> wrote:
    > >Walter Roberson wrote:
    > >>
    > >> In article <>,
    > >> pete <> 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
    pete, Jan 16, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Thomas_Gagn=E9?=

    Why do static and non-static method names collide?

    =?ISO-8859-1?Q?Thomas_Gagn=E9?=, Jul 2, 2003, in forum: Java
    Replies:
    12
    Views:
    5,631
    cgbusch
    Jul 5, 2003
  2. SaravanaKumar
    Replies:
    6
    Views:
    9,395
    Tony Morris
    Oct 19, 2004
  3. -
    Replies:
    6
    Views:
    413
    Tor Iver Wilhelmsen
    Jun 14, 2005
  4. oor
    Replies:
    0
    Views:
    1,346
  5. o_ssie
    Replies:
    0
    Views:
    315
    o_ssie
    Apr 9, 2009
Loading...

Share This Page