Dr. Memory unaddressable access and possible leak and still-reachable allocation from simple hello world

576 Views Asked by At

Basic hello world program using MinGW and gcc with no additional flags. I'm confused why I'm getting the errors 'unaddressable access', 'possible leak', and '4134 byte(s) of still-reachable allocation'.

Target: x86_64-w64-mingw32 using gcc version 8.2.0

#include <stdio.h>

int main() {
    printf("Hello World");
    return 0;
}

Error message from Dr. Memory: Error message from Dr. Memory

Shouldn't there be no errors at all from a simple program like this? Maybe if I could get some insight into what is going on.

1

There are 1 best solutions below

4
On

I think that when you want to print something on the screen you need to use, in general, int argc and argv[], specifically char *argv[] inside "()" after main since, of course you a string is an argument, and naturally. The program will be like:

#include <stdio.h>

int main(int argc, char *argv[]) {
    printf("Hello World");
    return 0;
}

Observe that now the program receives an argument of type char *argv[] and the number of them is being stored in argc. The unadressible was due, possibly, to the fact that it wasn't possible to know the size of the allocated array to be printed.