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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:26:02+00:00 2026-05-14T02:26:02+00:00

I’m updating some old code that has several POD structs that were getting zero’d

  • 0

I’m updating some old code that has several POD structs that were getting zero’d out by memset (don’t blame me…I didn’t write this part). Part of the update changed some of them to classes that use private internal pointers that are now getting wiped out by the memset.

So I added a [non-virtual] reset() method to the various structs and refactored the code to call that instead.

One particular struct developed an “undefined reference to `blah::reset()'” error.

Changing it from a struct to a class fixed the error.

Calling nm on the .o file h, the mangled function names for that method look the same (whether it’s a class or a struct).

I’m using g++ 4.4.1, on Ubuntu.

I hate the thought that this might be a compiler/linker bug, but I’m not sure what else it could be. Am I missing some fundamental difference between structs and classes? I thought the only meaningful ones were the public/private defaults and the way everyone thinks about them.

Update:
It actually depends on the way the it’s declared:

typedef struct
{
  ...
  void reset();
} foo;

won’t link.

struct foo
{
  ...
  void reset();
};

links fine.

So, maybe just a lack of understanding on my part about the way typedefs work in this context?

  • 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-14T02:26:02+00:00Added an answer on May 14, 2026 at 2:26 am

    I think that your problem (and I don’t have a standards quote to back this up) is that because your struct doesn’t have a name, your member function also does not have a globally identifiable name.

    Although you’re allowed to use a typedef name to introduce a member function definition, that member function must be part of a named type if you are going to be able to link it to a definition in a different TU.

    typedef struct S_ { void reset(); } S;
    
    void S::reset() // OK, but the function actually has id: S_::reset()
    {
        // ...
    }
    
    typedef struct { void reset(); } T;
    
    void T::reset() // OK, defintion of anonymous struct's reset(),
                    // but this isn't an id that can cross TUs.
    {
        // ...
    }
    

    Edit: This could be a gcc bug, though.

    7.1.3 [dcl.typedef] If the typedef declaration defines and unnamed class (…), the first typedef-name declared by the declaration to be that class type (…) is used to denote the class type (…) for linkage purposes only (3.5).

    Edit:

    Or gcc might be right. While the class has external linkage via its typedef name (3.5/4), a member function has external linkage only if the name of the class has external linkage. Although the class has external linkage and it has a name for linkage purposes only it is still an unnamed class, so it’s member functions have no linkage.

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

Sidebar

Ask A Question

Stats

  • Questions 365k
  • Answers 365k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Sessions on the server doesn't cross over, so the actual… May 14, 2026 at 4:23 pm
  • Editorial Team
    Editorial Team added an answer Use inheritance to your advantage. .items { /* common shared… May 14, 2026 at 4:23 pm
  • Editorial Team
    Editorial Team added an answer Look at the -popViewControllerAnimated: method. You might also look at… May 14, 2026 at 4:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.