Thread: Why can't we have a two storage with a single variable

  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    40

    Why can't we have a two storage with a single variable

    I wrote code with two storage class with a single variable. test result show that we can't we have a two storage with a single variable. anyone can explain Why can't we have a two storage with a single variable

    Code:
     #include <stdio.h>
    
    void fun ()
    {
    	static extern x = 0;
    	x++;
    	printf(" x = %d ", x);
    }
    int main()
    {
        fun();
    	return 0;
    }
    Test result
    Code:
      multiple storage classes in declaration specifiers  static extern x = 0;
      ^~~~~~

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Why would you expect that to make any more sense than say
    int float two_types;

    Because those are the rules.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2021
    Posts
    138
    The storage classes are mutually exclusive. For example, static means "cannot be seen from outside" (among other things), while extern means "can be seen from outside." So having something be both static and extern makes no sense - either it can be seen, or it cannot be seen.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-19-2019, 02:49 AM
  2. multiple condition for single variable in single line
    By merafiq in forum C Programming
    Replies: 2
    Last Post: 03-13-2016, 05:26 PM
  3. Register variable storage
    By onlynishant in forum C Programming
    Replies: 3
    Last Post: 05-30-2012, 02:35 AM
  4. Doubt regarding storage of a static variable
    By karthik537 in forum C Programming
    Replies: 6
    Last Post: 02-21-2012, 01:21 PM
  5. Need suggestions for control/variable storage structures
    By Sergeant82d in forum C Programming
    Replies: 3
    Last Post: 05-07-2011, 04:13 AM

Tags for this Thread