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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:38:10+00:00 2026-06-02T08:38:10+00:00

Why does valgrind reports on uninitialised bytes in the following code? #include <valgrind/memcheck.h> class

  • 0

Why does valgrind reports on uninitialised bytes in the following code?

#include <valgrind/memcheck.h>

class Test {
public:
    Test() {}
};

int main(int argc, char* argv[]) {
    Test a;
    VALGRIND_CHECK_VALUE_IS_DEFINED(a);
    return 0;
}

If I add a member variable to test and initialise it, there is no output.

  • 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-02T08:38:11+00:00Added an answer on June 2, 2026 at 8:38 am

    In your example, the size of ‘a’ will be 1:

    printf("%ld\n",sizeof(a)); => 1
    

    sizeof() only reports the data in a class, but since each unique class must have it’s own address, a padding byte is added. The reason valgrind complains is that you are accessing the padding byte, which the compiler has no obligation to initialize to any value.

    See here for a comment on why the minimum size of a class is 1 and not 0.

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

Sidebar

Related Questions

Say I have the following program #include <stdio.h> #include <stdlib.h> int main(void) { int
I am running memcheck using valgrind. the o/p is ==3091== 204 bytes in 17
When running valgrind on the following program the assertion fails: #include <unistd.h> #include <sys/mman.h>
#include <ctime> #include <iostream> #include <cstring> int main() { struct tm tm ; //memset(&tm,
valgrind is reporting uninitialized memory errors from code like this: unsigned char buf[100]; struct
Hi I am getting the the following error from valgrind. Conditional move based on
Does anyone know how to use Valgrind to memory debug RInside programs?
I have a lot of possible lost entry from valgrind. What does that mean
I have this output from valgrind: ==4836== 10,232 bytes in 1 blocks are still
Consider the following C++ program: #include <cstdlib> // for exit(3) #include <string> #include <iostream>

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.