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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:00:13+00:00 2026-06-03T06:00:13+00:00

Suppose I have the following class template: template<typename T> struct Wrapper { T* t_;

  • 0

Suppose I have the following class template:

template<typename T>
struct Wrapper {
  T* t_;
  static void check() {
    static_assert(sizeof(Wrapper<T> == sizeof(T*), "Illegal assumption");
  }
};

I looked in the C99 standard an in the C++03 standard and cannot find a guarantee for my assumption expressed in the static_assert. I tried it on Visual C++ 2008 and 2010 (32bit) and gcc on linux (64bit) using several compiler options and found my assumption confirmed.


My question are:

  • Is my assumption reasonable for Visual C++ 2008/2010/11 (windows)?
  • For gcc 4.* (linux)?
  • For any combination of compiler flags?
  • Do you know of any compiler/platform where this assumption does not hold true?

I guess a compiler might add some padding to the struct e.g. for debugging purposes. But is there a compiler that actually does that?

Edit: So as you asked here is what I want to achieve:

I have the member function with the following signature:

Someclass* OtherClass::fn();

I want to change the signature like this:

Wrapper<Someclass> OtherClass::fn();

This wrapper acts like some smart-pointer, i.e. it cares for the pointer’s lifetime, thus it releases it when it goes out of scope. As the function is called across a dll boundary I want to make sure that the returned value (which is now a concrete type, not just a dumb pointer) is in all circumstances (i.e. compiler settings, etc) of the same size as the pointer would be. The plan/hope is to support all combination of debug/release application/dll builds.

As you might ask: no, I can not use boost::shared_ptr<>, std::shared_ptr<>, std::unique_ptr<> and the like, as we don’t want to expose boost to the dll user and we don’t support C++11 yet.

  • 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-06-03T06:00:14+00:00Added an answer on June 3, 2026 at 6:00 am

    If you want to assume it and you have a compile-time check, then go ahead. Presumably you get some benefit out of doing this.

    You aren’t guaranteed anything about padding, but typically padding is used to get alignment so that arrays of the type have every member of the array (and every member of the struct) aligned properly. A native pointer is usually already the right size to be aligned, so padding isn’t needed, but you aren’t guaranteed that.

    This isn’t something you can just check with gcc — it depends on the target architecture, not only the compiler.

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

Sidebar

Related Questions

Suppose we have the following template class template<typename T> class Wrap { /* ...
Suppose I have the following classes: public class Test { public static void main(String[]
Suppose you have the following class: class Test : ISerializable { public static Test
Suppose I have the following: #include <iostream> #include <string> template<class T> class base {
Suppose I have following template class: template<unsigned char I, unsigned char F> class FOO
Suppose that I have following class template<unsigned char B, unsigned char F> class Foo
Suppose I have following template template<unsigned char I, unsigned char F> class FOO {
Suppose I have a class template <typename T> class A { public: template <typename
I have a dilemma. Suppose I have a template class: template <typename ValueT> class
Suppose i have a function template StrCompare template<typename T=NonCaseSenCompare>//NonCaseSenCompare is a user defined class

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.