R
RB
I am newbee novice programmer, and I ran across some strange outputs
in an app I was creating that I could not understand. So I reproduced the
strangeness in this very small app for posting.
It must have something to do with mixing printf and cout together in the same
function, which it appears one should not do that. I'm sure you will know what
is going on but I have never ran across this before.
I am compiling with MS VS 6.0 (and old version)
Appreciate any comments or input.
===== entire small app code below, outputs to follow ============
#include <windows.h>
#include <stdio.h>
#include <iostream.h>
struct Hold
{
DWORD pHeld;
} *pHold;
void FuncA( );
void FuncB( );
void main( )
{
DWORD FuncA_addr = (DWORD)FuncA;
__asm
{
push [FuncA_addr]
pop [pHold]
}
FuncA( );
FuncB( );
}
void FuncA( )
{
printf("Inside FuncA( )\n");
printf("printf Addr of FuncA( ) is 0x%X\n", pHold);
cout << "cout Addr of FuncA( ) is " << pHold << "\n";
}
void FuncB( )
{
printf("Inside FuncB( )\n");
}
===== end code, begin outputs ==================
output "should" be this
................................................
Inside FuncA( )
printf Addr of FuncA( ) is 0x40100A
cout Addr of FuncA( ) is 0x0040100A
.................................................
but instead I get two other outputs depending on whether
I run the app from command shell viewing output
OR
I run the app from command shell redirecting output to txt file
both scenarios shown below.
*------- running from command shell and viewing output
Inside FuncA( ) <-correct
printf Addr of FuncA( ) is 0x40100A <-correct
Inside FuncB( ) <-? not correct should print last ?
cout Addr of FuncA( ) is 0x0040100A <-? not correct should print third ?
*------- end command shell viewing output
*_____ running from command shell and redirecting output to txt file
cout Addr of FuncA( ) is 0x0040100A <-? not correct should print third ?
Inside FuncA( ) <-? not correct should print first ?
printf Addr of FuncA( ) is 0x40100A <-? not correct should print second ?
Inside FuncB( ) <-? not correct should print last ?
*________ end redirection to file
in an app I was creating that I could not understand. So I reproduced the
strangeness in this very small app for posting.
It must have something to do with mixing printf and cout together in the same
function, which it appears one should not do that. I'm sure you will know what
is going on but I have never ran across this before.
I am compiling with MS VS 6.0 (and old version)
Appreciate any comments or input.
===== entire small app code below, outputs to follow ============
#include <windows.h>
#include <stdio.h>
#include <iostream.h>
struct Hold
{
DWORD pHeld;
} *pHold;
void FuncA( );
void FuncB( );
void main( )
{
DWORD FuncA_addr = (DWORD)FuncA;
__asm
{
push [FuncA_addr]
pop [pHold]
}
FuncA( );
FuncB( );
}
void FuncA( )
{
printf("Inside FuncA( )\n");
printf("printf Addr of FuncA( ) is 0x%X\n", pHold);
cout << "cout Addr of FuncA( ) is " << pHold << "\n";
}
void FuncB( )
{
printf("Inside FuncB( )\n");
}
===== end code, begin outputs ==================
output "should" be this
................................................
Inside FuncA( )
printf Addr of FuncA( ) is 0x40100A
cout Addr of FuncA( ) is 0x0040100A
.................................................
but instead I get two other outputs depending on whether
I run the app from command shell viewing output
OR
I run the app from command shell redirecting output to txt file
both scenarios shown below.
*------- running from command shell and viewing output
Inside FuncA( ) <-correct
printf Addr of FuncA( ) is 0x40100A <-correct
Inside FuncB( ) <-? not correct should print last ?
cout Addr of FuncA( ) is 0x0040100A <-? not correct should print third ?
*------- end command shell viewing output
*_____ running from command shell and redirecting output to txt file
cout Addr of FuncA( ) is 0x0040100A <-? not correct should print third ?
Inside FuncA( ) <-? not correct should print first ?
printf Addr of FuncA( ) is 0x40100A <-? not correct should print second ?
Inside FuncB( ) <-? not correct should print last ?
*________ end redirection to file