[fpc-pascal] Linux library access violation

L505 fpcmail at z505.com
Mon Oct 30 08:06:49 CET 2006

> int testreturn(const char *thename, char *rcity, char *rstate)
> {
>      memcpy (rcity,"Boston",7);
>      memcpy (rstate,"Massachusetts",14);
> return strlen(thename);
> }

First thing to check.... is it declared CDECL or STDCALL in the C library?
I think the default C declaration mode is CDECL if it is not defined explicitely.

> I click OK and its fine. It returns everything correctly. That message
> box is a pain though. I tried:
> try
>   retint := testreturn(pchar(ganame), pchar(rlines[0]), pchar(rlines[1]));
> except
> //do something
> end;
> But the program just quits.

Whelp..exceptions are a false sense of security, and many elite programmers refuse to use them
because they are like GOTO statements (Chen, Spolsky, and others). It's even worse when you
cover things up like using
  //do something
instead of handling the exception.  Whereas if you skip exceptions all together, and just do
real checks with regular code, old school error codes - it might end up being more of a solid
program. However, this is no place for exception pros/cons flamewars ;-)

In general, for troubleshooting a problem in these beginning stages, I wouldn't even use
exceptions - they just complicate things until you find the error using other trial and error
code checks such as:
-  nil checks.. is something nil, why?
-  length checks.. is the pchar the right length before and after, or is it damaged somewhere?
-  sizeof checks..
-  declaration checks
-  operating system error checks such as getlasterror (in this case it don't help, but in
-  other trial and error through real code instead of exception code

More information about the fpc-pascal mailing list