Recent

Author Topic: FPC 3.2.2 - C stdin, stdout and stderr could not be imported.  (Read 207 times)

paule32

  • Sr. Member
  • ****
  • Posts: 277
FPC 3.2.2 - C stdin, stdout and stderr could not be imported.
« on: October 30, 2024, 04:11:21 pm »
i have the following code:

Code: Pascal  [Select][+][-]
  1. var
  2.     __stdin : Pointer; cdecl; external 'msvcrt.dll' name 'stdin' ;

and I get the following error message:
Code: Text  [Select][+][-]
  1. Fatal: Syntax error, ":" expected but ";" found

Thaddy

  • Hero Member
  • *****
  • Posts: 15992
  • Censorship about opinions does not belong here.
Re: FPC 3.2.2 - C stdin, stdout and stderr could not be imported.
« Reply #1 on: October 30, 2024, 04:22:26 pm »
You wrote the code the other way around and more specific stdin already exists in freepascal as an alias for input.

try this:
Code: Pascal  [Select][+][-]
  1. var
  2.     mystdin : Pointer; external 'msvcrt.dll' name '__stdin' ;
And stdin is a textfile, and in C a handle, not a pointer, even my code won't work but puts you on the right track.
Pointers also do not need a calling convention. Also mind trailing spaces...
Btw, why would you need stdin from msvcrt? that does not make any sense at all. It is in system and part of any pascal program.
(btw, I can detect the use of AI, I smell it..., tell me I am wrong)
« Last Edit: October 30, 2024, 04:41:33 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

MarkMLl

  • Hero Member
  • *****
  • Posts: 7894
Re: FPC 3.2.2 - C stdin, stdout and stderr could not be imported.
« Reply #2 on: October 30, 2024, 04:42:44 pm »
You wrote the code the other way around and more specific stdin already exists in freepascal as an alias for input.

There are two separate things here: System.StdIn as a documented alias for Input (i.e. semi-magical as a program parameter), and the well-known handles stdin etc. which have special meaning in the context of many OSes.

I would presume that in the case of msvcrt it's a (function returning a?) numeric constant, but this is somewhere where one has to be very cautious.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

paule32

  • Sr. Member
  • ****
  • Posts: 277
Re: FPC 3.2.2 - C stdin, stdout and stderr could not be imported.
« Reply #3 on: October 30, 2024, 04:43:12 pm »
Hi Thaddy,

yes, you right - from msvcrt.dll
I use some C-Functions in an Application that need the **stdin** for **fgets** and others.

Edit:

@MarkMLI  ;D
under Windows, you are faced with STD_INPUT_HANDLE from the win32API and the C-Functions like fgets or fopen - which comes from historically reason.
Because Microsoft does write the OS with C (I guess).

And as such, you have two Versions for low-level C-Function's, and the high-level API functions.
Last but not least: the calling convention's stdcall (Pascal), and cdecl for C/C++.
« Last Edit: October 30, 2024, 04:50:38 pm by paule32 »

Thaddy

  • Hero Member
  • *****
  • Posts: 15992
  • Censorship about opinions does not belong here.
Re: FPC 3.2.2 - C stdin, stdout and stderr could not be imported.
« Reply #4 on: October 30, 2024, 05:06:38 pm »
fgets and family work happily with fpc's stdin.
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018