Recent

Author Topic: Error: Identifier not found "result"  (Read 13118 times)

song shuang

  • Newbie
  • Posts: 3
Error: Identifier not found "result"
« on: October 22, 2018, 01:58:34 pm »
Hi,
Maybe a simpler question. :D
two unit:

Library foo;
uses
  ctypes, math, func;
function GetEeprom(src: pcint32):cint; cdecl;
  begin
    GetEeprom := getsum(src);
  end;
exports
   GetEeprom;
begin
  SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]);
end.

unit func;
interface
uses SysUtils, Variants, Classes;
function getsum(src:pointer):integer;
implementation
function getsum(src:pointer):integer;
begin
  result := 88;
end;
end.

command line:
ppcx64-3.0.5 -Tiphonesim -XR/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk -Cn foo.pas -FU./sim -Fu./mysrc
Free Pascal Compiler version 3.0.5 [2017/11/26] for x86_64
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Darwin/iPhoneSim for x86_64
Compiling foo.pas
Compiling ./mysrc/func.pas
func.pas(13,3) Error: Identifier not found "result"
func.pas(17) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

why the keywords of pascal ,"result" can not be identified?
Thanks for your help!
Best Regards,

rvk

  • Hero Member
  • *****
  • Posts: 6387
Re: Error: Identifier not found "result"
« Reply #1 on: October 22, 2018, 02:04:29 pm »
If you don't specify a mode it will compile with {$mode fpc}
And FPC-mode does not recognize Result as result for a function.
You can read on this page the Result is only recognized by objfpc and delphi modes.
https://www.freepascal.org/docs-html/3.0.2/ref/refse90.html

So either specify the mode in the source:
{$mode objfpc} // or other mode

Or specify it on the command line and add -Mobjfpc to the parameters.

Xor-el

  • Sr. Member
  • ****
  • Posts: 404
Re: Error: Identifier not found "result"
« Reply #2 on: October 22, 2018, 02:07:56 pm »
if I remember correctly, the keyword "result" is only recognized in mode ObjFPC and mode Delphi.

See the corrected code.

Code: Pascal  [Select][+][-]
  1. library lib;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   ctypes,
  7.   Math,
  8.   func;
  9.  
  10.   function GetEeprom(src: pcint32): cint; cdecl;
  11.   begin
  12.     GetEeprom := getsum(src);
  13.   end;
  14.  
  15. exports
  16.   GetEeprom;
  17. begin
  18.   SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]);
  19. end.
  20. end.
  21.  

and unit func


Code: Pascal  [Select][+][-]
  1. unit func;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses SysUtils, Variants, Classes;
  8.  
  9. function getsum(src: pointer): integer;
  10.  
  11. implementation
  12.  
  13. function getsum(src: pointer): integer;
  14. begin
  15.   Result := 88;
  16. end;
  17.  
  18. end.
  19.  

Thaddy

  • Hero Member
  • *****
  • Posts: 15704
  • Censorship about opinions does not belong here.
Re: Error: Identifier not found "result"
« Reply #3 on: October 22, 2018, 02:14:13 pm »
Yes, but you can also do this:
Code: Pascal  [Select][+][-]
  1. unit xxx;{$modeswitch result}
If I smell bad code it usually is bad code and that includes my own code.

song shuang

  • Newbie
  • Posts: 3
Re: Error: Identifier not found "result"
« Reply #4 on: October 22, 2018, 02:19:42 pm »
thank for rvk!
i has been looked for a method to create a static library for ios for some days.
test it successful on iphone sim,Not yet test in real iphone.
------
ar -q paslib.a `grep "\.o$" link.res`
ranlib paslib.a

 

TinyPortal © 2005-2018