• (2 Pages)
  • +
  • 1
  • 2

Printf V/s Cout [DreamInCode.net] Which one is better? Rate Topic: ***-- 3 Votes

#16 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 175
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Posted 08 May 2008 - 07:01 AM

When a member function of an object is called, the this pointer is passed as an argument on the stack (The order depends on the calling convention) and a lot of work is done on the this pointer to check which object is calling the function.

Standard Functions just need a simple CALL instruction.
Was This Post Helpful? 0
  • +
  • -

#17 mikeblas  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 390
  • Joined: 08-February 08

Posted 08 May 2008 - 11:47 PM

View Postborn2c0de, on 8 May, 2008 - 07:01 AM, said:

When a member function of an object is called, the this pointer is passed as an argument on the stack

In some architectures, I suppose it is; but when using Visual C++ on X86 or IA64, __thiscall says that the this pointer arrives at the calling function arrives in the ECX register.

View Postborn2c0de, on 8 May, 2008 - 07:01 AM, said:

Which architecture presents (The order depends on the calling convention) and a lot of work is done on the this pointer to check which object is calling the function.
A lot of work? Like what? Why does the caller matter to the called function?

View Postborn2c0de, on 8 May, 2008 - 07:01 AM, said:

Standard Functions just need a simple CALL instruction.
I guess so, but it depends on what you mean by "Standard Functions".
Was This Post Helpful? 1
  • +
  • -

#18 codesrock  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 03-November 08

Posted 04 November 2008 - 01:49 AM

nice article...
good to see diff b/w printf and cout
Was This Post Helpful? 0
  • +
  • -

#19 homemade-jam  Icon User is offline

  • Gabe's Nemesis
  • member icon

Reputation: 10
  • View blog
  • Posts: 1,300
  • Joined: 17-March 08

Posted 04 November 2008 - 02:12 AM

Born and bred on cout :^:
Was This Post Helpful? 0
  • +
  • -

#20 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 278
  • View blog
  • Posts: 1,588
  • Joined: 15-May 08

Posted 16 April 2009 - 09:31 PM

Just on the fact that cout is an object with a bunch of member functions and printf is a function... Bit confused, how big is the function of printf ? I mean when you pass paramters such as %d, %i ... what then is called to manipulate the data ? This might be something very simple, however i really would like to know .... like when printf(%d, something) is called - is a function called within printf to change the "something" and return it to printf to print ?

I guess this could be traced in olley or ida, however i am unsure
Was This Post Helpful? 0
  • +
  • -

#21 mikeblas  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 43
  • View blog
  • Posts: 390
  • Joined: 08-February 08

Posted 18 April 2009 - 06:15 PM

View Postbbq, on 16 Apr, 2009 - 08:31 PM, said:

.... like when printf(%d, something) is called - is a function called within printf to change the "something" and return it to printf to print ?

I guess this could be traced in olley or ida, however i am unsure
No reason to trace through it in a disassembler. You can download the code for a number of printf() implementations from any Linux distro you like. If you have Visual C++ in Windows, you've got the source code for all of the run-time library routines on your hard drive already (if you installed them; they're on the DVD). You can even step into the functions and watch them work under the debugger.

The answer is that, yes: printf() calls other functions to do formatting for each of the escape codes it uses. Depending on the implementation, it might do so directly--but it probably calls another helper function that lets the library share code. printf(), fprintf(), sprintf(), vsprintf(), and so on, all use the same formatting escapes, so they're all implemented by shared routines ... in a well-built library, anyhow.
Was This Post Helpful? 1
  • +
  • -

#22 DaneAU  Icon User is offline

  • Great::Southern::Land
  • member icon

Reputation: 278
  • View blog
  • Posts: 1,588
  • Joined: 15-May 08

Posted 19 April 2009 - 01:12 AM

View Postmikeblas, on 18 Apr, 2009 - 05:15 PM, said:

View Postbbq, on 16 Apr, 2009 - 08:31 PM, said:

.... like when printf(%d, something) is called - is a function called within printf to change the "something" and return it to printf to print ?

I guess this could be traced in olley or ida, however i am unsure
No reason to trace through it in a disassembler. You can download the code for a number of printf() implementations from any Linux distro you like. If you have Visual C++ in Windows, you've got the source code for all of the run-time library routines on your hard drive already (if you installed them; they're on the DVD). You can even step into the functions and watch them work under the debugger.

The answer is that, yes: printf() calls other functions to do formatting for each of the escape codes it uses. Depending on the implementation, it might do so directly--but it probably calls another helper function that lets the library share code. printf(), fprintf(), sprintf(), vsprintf(), and so on, all use the same formatting escapes, so they're all implemented by shared routines ... in a well-built library, anyhow.


Cheers for the info :) I did actually have a look through the vs libraries which explained a fair bit - thanks for the response :)
Was This Post Helpful? 0
  • +
  • -

#23 DoEds  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-June 09

Posted 30 June 2009 - 07:41 AM

Yea i like printf...Its much easier...
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2