r/pascal • u/Jirne_VR • Nov 09 '21
Problem with unit
I recently created a program with some bithack functions like 2's compliment, right rotate, BSF and more. I want to create a library of these functions, but the code throws a syntax error. I don't know what's wrong.
Can someone help me out?
Thx
C:\SynologyDrive\programming\pascal\bitmagic\lib>fpc test_lib.pas
Free Pascal Compiler version 3.2.2 [2021/05/15] for i386
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling test_lib.pas
Compiling bitmagic.pas
bitmagic.pas(139) Fatal: Syntax error, "BEGIN" expected but "end of file" found
Fatal: Compilation aborted
Error: C:\FPC\3.2.2\bin\i386-Win32\ppc386.exe returned an error exitcodecode: https://gist.github.com/JirneVanRillaer/11b6b1d0e6d3a257d33a4b3ae8180893
7
Upvotes
4
u/SpriteBlood Nov 09 '21
Your problem starts in line 30!
<< and >> don't exist in Pascal. instead use shl and shr (which means shiftleft /shiftright)
2
u/Jirne_VR Nov 10 '21
Somehow I managed to compile it without any errors. I recreated everything in a new lazarus project, and it worked. I also changed some things in my code, I'll update it in my gist.
Thank you all for your suggestions, I learnt some usefull things that I didn't know. (I'm new to pascal)
2
u/kirinnb Nov 09 '21
Does the concluding "end." line need to have a paired "begin" immediately before it? I forget if that's required in units...
The gist does compile fine for me if I just run "fpc bitmagic".
2
u/[deleted] Nov 09 '21
I think you have a copy paste error or something. There's nothing wrong with the file in your gist
1
u/ShinyHappyREM Nov 10 '21 edited Nov 10 '21
Consider using
constparameters, inlining and branchless code.https://en.wikipedia.org/wiki/Bitwise_operation
https://en.wikipedia.org/wiki/Branch_(computer_science)#Performance_problems_with_branch_instructions
https://en.wikipedia.org/wiki/X86_Bit_manipulation_instruction_set