* * *

Author Topic: how to gain access to printf ?  (Read 162 times)

440bx

  • Jr. Member
  • **
  • Posts: 60
how to gain access to printf ?
« on: July 11, 2018, 02:41:42 pm »
Hello,

I am currently reading the Reference Manual and executing the examples that are presented there.  On page 196, there is an example to show how to use "array of const" with a C function.  The program is as follows:

Code: Pascal  [Select]
  1. program testaocc;
  2. {$mode objfpc}
  3. Const
  4. P : PChar = ’example’;
  5. Fmt : PChar =
  6. ’This %s uses printf to print numbers (%d) and strings.#10;
  7. // Declaration of standard C function printf:
  8. procedure printf (fm : pchar; args : array of const);cdecl; external ’c’;
  9. begin
  10. printf(Fmt,[P,123]);
  11. end.

The program compiles but won't load/run because "c.dll" is missing.  The complaint that c.dll is missing makes sense but, something tells me the example was meant to work and I may be missing something. 

My question is: what changes are needed in the above example to make it run ?

NOTE: I can get the example to work by modifying the printf declaration to be as follows:
Code: Pascal  [Select]
  1. const
  2.   user32 = 'user32.dll';
  3.  
  4.   procedure printf (Output,
  5.                     Format : pchar; args : array of const); cdecl;
  6.                     external user32 name 'wsprintfA';
but that seems too far from the original declaration to believe that was its original intent.

From what I've learned about FPC so far, I am under the impression that it statically links with a C library (I could easily be wrong about that).  Was the declaration in the example meant to provide access to the printf function which may be included in that library ?  (I'm just guessing...  just wondering what the intent of the declaration in the example is/was)

Thank you for your help.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6333
Re: how to gain access to printf ?
« Reply #1 on: July 11, 2018, 03:33:38 pm »
That declaration is for *nix, so more the Kylix compatibility thingy. On *nix linking with C runtimes is more common.

this is the first question for it on Windows, what do you need this for ?  In general writeln and format is considered enough.

440bx

  • Jr. Member
  • **
  • Posts: 60
Re: how to gain access to printf ?
« Reply #2 on: July 11, 2018, 06:50:15 pm »
That declaration is for *nix, so more the Kylix compatibility thingy. On *nix linking with C runtimes is more common.

this is the first question for it on Windows, what do you need this for ?  In general writeln and format is considered enough.

Thank you.  That makes perfect sense.   

I need it only to the extent that I want to be aware of all the compiler's capabilities.    FPC really has a nice set of features of its own.


 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus