static structs

This is a discussion on static structs within the C Programming forums, part of the General Programming Boards category; Just a random question about static structs for example: Code: static struct info { double number; }; since this struct ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    17

    static structs

    Just a random question about static structs

    for example:

    Code:
    static struct info
    {
    double number;
    };
    since this struct is static shouldn't I be able to reference data members without initialization?

    ie:

    Code:
    info.number = 1;
    printf("%d", info.number);
    is something like this even possible?
    Last edited by aosmith; 03-22-2010 at 05:46 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Whatever you're doing with that top code box, knock it off. It's hard to read.

    No, static in C isn't the same as making static members in C++. Static defines the scope of the variable. You aren't actually declaring a variable, so how you are using static is wrong, and, your compiler will tell you as much.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    17
    Thanks Quzah,

    ... I'm not sure what happened with the top code box (I assume you're talking about the fact that it scrolls), I guess I shouldn't have used the indent tag inside of a code tag... Maybe one of the mods or admins can address this issue?

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by aosmith View Post
    Code:
    info.number = 1;
    printf("%d", info.number);
    is something like this even possible?
    It's non-sensical , since "info" (properly, struct info) is a type, like:

    Code:
    int.number = 1;
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 01:22 PM
  3. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  4. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21