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

  • Home
  • SEARCH
  • 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 6235499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:40:41+00:00 2026-05-24T10:40:41+00:00

In other words can I be sure that my program is undefined behaviour free

  • 0

In other words can I be sure that my program is undefined behaviour free if it runs without any Valgrind error messages?

  • 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-24T10:40:42+00:00Added an answer on May 24, 2026 at 10:40 am

    There is a fundamental error here.

    Valgrind is not some sort of static analysis tool that understand the semantics of the C++ grammar and thus know when you are invoking Undefined Behavior as specified by the C++ Standard.

    Valgrind is a tool that will however alert you whenever you are doing operations in the memory that are the results of the Undefined Behavior of your program. For example, it will detect whenever you access unallocated or freed memory, it will detect when you make a system call with an uninitialized (or partly unitialized) value/buffer, etc…

    To take a medical analogy, Valgrind detects the symptoms of Undefined Behavior. The absence of symptoms does not imply the absence of Undefined Behavior.

    Furthermore, because Valgrind only ever inspect code that runs, it will leave some “code” uninspected.

    Getting rid of Undefined Behavior is extremely complicated. If your program is non-trivial, it is likely to be equivalent to solving the Halting Problem. However, that should not prevent you from taking precautions:

    • Turn on compiler warnings: -Wall -Werror is a given, -Wextra is great (in addition) for new codebases (Elementary)
    • Use static analysis tools (several of them, since they do not report the same issues), Clang Static Analyzer, Purify, etc.. (Good Practice)
    • Run Valgrind on an extensive test-suite (you can use gcov to check the coverage)(Good Practice)
    • Read several Coding Standards, and think about their advice (do not apply them nilly willy), Sutter’s come first, High Quality CPP or MISRA are much more stricter and extensive. Some automatic code review tools can check such a set of rules. (Nice, and rewarding on a personal level)

    Once you’ve done all that, you’ve probably uncovered most of the technical errors within your program. Some, unfortunately, may be latent still. They may be exposed, one day, following a change of optimization options, a refactoring, or whatever… For stronger guarantees, you’ll need another language.

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

Sidebar

Related Questions

In other words, can fn() know that it is being used as $var =
In other words, can I do something with a volatile variable that could not
To print debug messages in my program, I have a that can be used
In other words, can I do something like for() { for { for {
Can an XML attribute be the empty string? In other words, is <element att=
Does updating statistics cause tables to be inaccessible? In other words, can you run
I'm writing a program that, among other things, needs to display a context menu
I have wrote a server program that can handle multiple client by using fork().
I can't believe it,this works in my other application,but in this one,which has similiar
In other words, is this Singleton implementation thread safe: public class Singleton { private

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.