Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6918085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:48:50+00:00 2026-05-27T09:48:50+00:00

Here is my setup: In public.h: #ifndef PUBLIC_H_ #define PUBLIC_H_ #include func.h /*extern typedef

  • 0

Here is my setup:

In public.h:

#ifndef PUBLIC_H_
#define PUBLIC_H_

#include "func.h"

/*extern typedef struct _my_private_struct PRIVATE_;*/
typedef struct _my_private_struct PRIVATE_; /* Thanks to larsmans and Simon Richter */
#endif

In struct.h

#ifndef STRUCT_H_
#define STRUCT_H_

struct _my_private_struct {
    int i;
};
#endif

In func.h:

#ifndef FUNC_H_
#define FUNC_H_
#include "struct.h"

/* typedef struct _my_private_struct PRIVATE_; */
extern PRIVATE_ * get_new(int);
#endif

In func.c:

#include <stdlib.h>
#include "func.h"

PRIVATE_ * get_new(int i)
{
    PRIVATE_ *p = (PRIVATE_ *) malloc(sizeof(PRIVATE_));
    if (p == NULL) return NULL;

    p->i = i;

    return p; 
}

In main.c:

#include "public.h"

int main(int argc, char ** argv)
{
    PRIVATE_ *p = get_new(2);
    return 0;
}

When I compile those file with GCC I’m getting this error:

OLD COMPILE ERROR

multiple storage classes in declaration specifiers

COMPILE ERROR AFTER EDIT

expected ‘=’, ‘,’, ‘;’, ‘asm’, or ‘__attribute__’ before ‘*’ token

Can someone help me out/explain why I’m getting this and how to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:48:50+00:00Added an answer on May 27, 2026 at 9:48 am

    The other answers cover your problem pretty well. However, allow me to add to them and answer your latest comment:

    I’m getting compile error: in public.h: redefinition of typedef PRIVATE_…

    While the error is self-explanatory it’s probably less clear why that’s happening. Consider what happens when you include public.h:

    #include "struct.h"
    #include "func.h"
    typedef struct _my_private_struct PRIVATE_;
    

    If you trace through this and fully expand the preprocessor, this is what you’ll get:

    // struct.h
    struct _my_private_struct
    {
        int i;
    };
    
    // func.h
    typedef struct _my_private_struct PRIVATE_;
    extern PRIVATE_ * get_new(int);
    
    // public.h
    typedef struct _my_private_struct PRIVATE_;
    

    It should now be obvious why you’re running into problems. Without the typedef in func.h, your get_new prototype fails because it hasn’t seen PRIVATE yet. OTOH, if you leave the typedef in you’ve defined it twice.

    Also, it looks like you’re trying to keep that structure private from other code and modules. Even if you do fix the build errors you haven’t really achieved that encapsulation. Consider this:

    int main()
    {
        PRIVATE_ *p = get_new(2);
        p->i = 1337;        // HAHA, I just modified your private i.
                            // what are you going to do about it?
    }
    

    If you want data privacy in C consider an opaque pointer design. I recommend restructuring your source like this:

    // public.h
    #ifndef PUBLIC_H_
    #define PUBLIC_H_
    
    #include "func.h"
    
    #endif
    

    // func.h
    #ifndef FUNC_H_
    #define FUNC_H_
    
    struct PRIVATE_NOT_ACCESSIBLE;
    typedef struct PRIVATE_NOT_ACCESSIBLE myint_t;
    
    // declare your struct methods here
    myint_t* get_new(int);
    // ..
    
    #endif
    

    // func.c
    #include <stdlib.h>
    #include "func.h"
    
    // define this only with functions 
    // that's suppose to work with its internal data
    struct PRIVATE_NOT_ACCESSIBLE
    {
        int i;
    };
    
    myint_t * get_new(int i)
    {
      // ...
    }
    

    Now if you try this:

    #include "public.h"
    
    int main()
    {
        myint_t *p = get_new(2);
        p->i = 1337;            // Aw, doesn't work anymore :(
    }
    

    Edit: To answer the OP’s comment below.

    If you have private struct’s methods implemented in more than one compilation unit you can still make it work by moving private’s definition to a dedicated header:

    // func_implementation.h
    #include "func.h"
    struct PRIVATE_NOT_ACCESSIBLE
    {
        int i;
    };
    // internal methods, helper functions you don't want exposed should go here too.
    // eg.
    void helper_method(myint_t *);
    

    Source files that implement your struct private ‘object’ will include ‘func_implementation.h’. External client code that uses private will include ‘func.h’ only.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my table setup: public static final String TABLE_DEBT = debt; public static
Here's the setup: public class Parent { public List<Child> ChildrenA = new List<Child>(); public
Okay, here's the setup: EnclosingClass { public interface ClassFactory { public static SomeClass getInstance(int
I need to set up an amazon server. I always here setup ubuntu on
I have a page that i have been starting to setup here http://www.brandybrowauto.com/NEW.html that
Here is my setup: I have modeled my application after the SportsStore in Pro
Here is my setup, it seems I am not binding the data correctly. The
Here's the setup. I have a custom UIScrollView as a subview of PrimeView. The
Here's the setup. I have web site which is essentially a simple CMS. Here
Here's the setup : http://jsfiddle.net/AndyMP/rVrjY/ What I'd like to achieve is a shadow on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.