Results 1 to 3 of 3

Thread: Declare Public Variables in C

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    Declare Public Variables in C

    How do I declare a public array or other variables using C?

    I need to know syntax and placement of code...

    thanx,

    Squirrelly1
    Now happily married and still crankin' away at the keyboard. Life is grand for a coder, no?

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    No such things as access specifiers in C. Just declare a global variable somewhere (not inside a function).

    syntax of variable declarations:
    storage-class-specifier type-specifier variables;

    storage-class-specifier: static | extern | volatile | register | auto

    type-specifier: [const] (default types | structs | unions | typedefs)

    variables: variable{, variable...}

    variable: [* [const]] identifier[\[size\]][= initialValue]

    initialValue: literal

    identifier: /[A-Za-z_][A-Za-z0-9_]*/

    size: constant positive integer

    Did I miss something? I made it up myself, it's not copied or anything...
    Last edited by CornedBee; Dec 9th, 2002 at 08:19 AM.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    An example:

    Code:
    #include <stdio.h>
    int global_value=1;  // outside of any function or in the header file
    
    int main(){
          int local_value;  // inside a function
          local_value=2;
          printf("local_value: %d global_value: %d\n",
                           local_value, global_value);
          return 0;   
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width