0
           rc = daoMp.retrieveSystemData(argv[2]);
           printf("rc = %d\n");
           if (rc == 0) {
               ErrLog("Mount point found\n");
               printf("Mount point found\n");
               return 4;
           }
           else {
               ErrLog("Could not retrieve system data\n");
               printf("Could not retrieve system data\n");
               return -1;
           }

Output: rc = -208814497
Mount point found

How come, if block validation fails?

RajSanpui
  • 11,556
  • 32
  • 79
  • 146
  • 4
    look at your first printf. more carefully. – Hayri Uğur Koltuk Feb 05 '14 at 15:36
  • 1
    You have evoked Undefined Behavior best avoided by not using crappy, type-unsafe C-style calls in the first place. – John Dibling Feb 05 '14 at 15:40
  • Sorry, i didn't understand. There are other parts of code that uses something like `if (rc < 0)` and i followed the same. What do i miss here? Can someone help me? – RajSanpui Feb 05 '14 at 15:44
  • look at the answers. rc equals to zero but you don't print rc, you print garbage (-208814497) – Hayri Uğur Koltuk Feb 05 '14 at 15:47
  • You're writing in C++, but this code reads like C. The answer is easy: [don't write like it were C](http://stackoverflow.com/questions/5328873/c-streams-vs-c-style-io). For a newbie the C-style is much more error prone, and I highly discourage it for people with little experience. – Kuba hasn't forgotten Monica Feb 05 '14 at 16:36

3 Answers3

5

Instead of this (which you're calling incorrectly, one argument too short):

printf("rc = %d\n");

Do this:

std::cout << "rc = " << rc << '\n';

That way, you'll use the proper C++ way of doing this (which would immediately tell you something's off). printf() is inherited from C and it's inherently unsafe - your error is a prime example of why.

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455
1

I believe you are missing second parameter to printf:

printf("rc = %d\n", rc);
Hayri Uğur Koltuk
  • 2,970
  • 4
  • 31
  • 60
0

printf("rc = %d\n"); should be printf("rc = %d\n", rc);

Sunil Bojanapally
  • 12,528
  • 4
  • 33
  • 46