Why it can work in windows but can't work in Linux? : <p>My code is as follows.</p>

<p>When I use Visual Studio to compile , debug and execute, it's right. And when I use 'gcc' to compile , it's also right, but it's wrong when execute in Linux. The memory is wrong when it run.</p>

<p>And when print 'szBuf', the wrong is can't access the memory.</p>

<p>I want to know why it can work when in Windows but can't work in Linux?</p>

<pre><code>#include &lt;stdio.h&gt;

void ItoA(int nNum, char *pStr);
void Print(const char *pFormat, ...);

int main()
{
    char  ch = 'a';
    int nNum = 11;
    char szBuf[255] = "";

    Print("ch: %c\n", ch);
    Print("n: %d\n", nNum);
    Print("s: %s\n", szBuf);

    return 0;
}

void ItoA(int nNum, char *pStr)
{
    if (NULL != pStr)
    {
        char szNum[255] = "";
        int i = 0;

        for (i = 0; 0 != nNum; i++)
        {
            szNum[i] = nNum % 10 + '0';
            nNum /= 10;
        }

        for (i = i - 1; i &gt;= 0; i--, pStr++)
        {
            *pStr = szNum[i];
        }
        *pStr = '\0';
    }
}

void Print(const char *pFormat, ...)
{
    if (NULL != pFormat)
    {
        char *pTemp = (char *)&amp;pFormat;
        pTemp += 4;

        while ('\0' != *pFormat)
        {
            if ('%' == *pFormat)
            {
                pFormat++;
                switch (*pFormat)
                {
                case 'c':
                {
                    putchar(*pTemp);
                    pTemp += 4;
                }
                break;
                case 'd':
                {
                    char szBuf[255] = "";
                    int nNum = 0;

                    ItoA(*(int *)pTemp, szBuf);

                    for (int i = 0; '\0' != szBuf[i]; i++)
                    {
                        putchar(szBuf[i]);
                    }

                    pTemp += 4;
                }
                break;
                case 's':
                {
                    for (int i = 0; '\0' != (*(char **)pTemp)[i]; i++)
                    {
                        putchar((*(char **)pTemp)[i]);
                    }

                    pTemp += 4;
                }
                break;
                default:
                {
                    pFormat--;
                    putchar(*pTemp);
                }
                break;
                }
            }
            else
            {
                putchar(*pFormat);
            }
            pFormat++;
        }
    }
}
</code></pre>
