Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What happens looks like this.</p> <pre><code>printf("%d", m); </code></pre> <p>On most systems the address of the string will get pushed on the stack, and then <code>'m'</code> as an integer (assuming it's an int/short/char). There is no warning because <code>printf</code> is basically declared as <code>'int printf(const char *, ...);'</code> - the ... meaning 'anything goes'.</p> <p>So since 'anything goes' some odd things happen when you put variables there. Any integral type smaller than an int goes as an int - things like that. Sending nothing at all is ok as well.</p> <p>In the printf implementation (or at least a 'simple' implementation) you will find usage of <code>va_list</code> and <code>va_arg</code> (names sometime differ slightly based on conformance). These are what an implementation uses to walk around the '...' part of the argument list. Problem here is that there is NO type checking. Since there is no type checking, <code>printf</code> will pull random data off the execution stack when it looks at the format string <code>("%d")</code> and thinks there is supposed to be an <code>'int'</code> next.</p> <p>Random shot in the dark would say that the function call you made just before printf possibly passed <code>'m-1'</code> as it's second parm? That's one of many possibilities - but it would be interesting if this happened to be the case. :)</p> <p>Good luck.</p> <p>By the way - most modern compilers (GCC I believe?) have warnings that can be enabled to detect this problem. Lint does as well I believe. Unfortunately I think with VC you need to use the /analyze flag instead of getting for free.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload