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 6252721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:51:23+00:00 2026-05-24T13:51:23+00:00

(I am talking about C, but it also applies to class templates in C++)

  • 0

(I am talking about C, but it also applies to class templates in C++)

In header file, it is a custom to put all the DECLARATIONS, not definitions. However, we usually put structure definitions or class templates in header file as well without actually knowing why we can. This doesn’t really make sense because they are definitions as well — ONE DEFINITION RULE. (Yes, structure definitions and class templates don’t cause any storage to set, but you still get “redefinition” error below which implies that they are definitions).

EX) defining multiple structures with same tag within same file give you a redefinition error, but defining multiple structures with same tag in multiple source files don’t cause any error (same thing happens with class).

The only thing that makes sense is that structure definitions and class templates have internal linkage (opposed to default external linkage), but I can’t find any references about it in K&R or reference manual.
In fact, structures are not even mentioned in linkage.

I want to know the exact reference where ANSI standard points out this pheonomenon.
(IMO, this is a pretty ambiguous thing which HAS TO be mentioned in ANSI standard somewhere).


EDIT
I am NOT asking why structure definitions can be put into the header file.

I am asking why putting structure definition in header file won’t cause redefinition error like it does when we put variable definitions in header file (and include it in multiple source files)

EX)
test1.c: int a = 3;
test2.c: int a = 4;
Causes compile error because of redefinition. However,

test1.c: struct test { int a };
test2.c: struct test { int b };
Does not cause compile error, and the only reason I can come up with is that
structure definitions either have internal linkage, or no linkage at all.

  • 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-24T13:51:24+00:00Added an answer on May 24, 2026 at 1:51 pm

    In C only objects and functions have linkage. Since struct in C may not contain functions or “static” member objects as in C++ your question makes not much sense, here.

    Member functions in C++ as long as they are not defined but only declared inside the struct pose no problem. If they are also defined, they are inline. The concept of inline was just invented for C++ to capture that case: a function definition that can be shared through a header file in several compilation units. C99 that adopted that concept (modifying it slightly).

    static member objects pose indeed more of a problem. The syntax on how to instantiate these guys is quite obscure, especially for template classes or structs. If you’d like to know about that one you’d have to ask for that, tagged specifically with C++.

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

Sidebar

Related Questions

I am not talking about the highlight colors but the actual colors. I got
I'm talking about operators which not return a value but modify (overwrite) the first
I'm obviously not talking about a full solution, but just a good starting point
I'm not talking about the kind you get in college, but rather implementing progress
Talking about javax.crypto.Cipher I was trying to encrypt data using Cipher.getInstance(RSA/None/NoPadding, BC) but I
On episode #162 of Hanselminutes they were talking about PowerShell, but more importantly around
How can I do what they are talking about here , but in Ruby?
I've read a few articles talking about checkboxes always returning a false state, but
There is this example code, but then it starts talking about millisecond / nanosecond
I don't know if variadic is actually the right word, but I'm talking about

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.