RE: [fpc-pascal]use of funct identifier in funct body

2003-09-03 Thread Balázs Csaba
If i know good, the result variable exists in function without declare it.
Use result instead function name.

#Tsch : Balázs Csaba 


> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of 
> Peter Vreman
> Sent: Wednesday, September 03, 2003 8:15 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [fpc-pascal]use of funct identifier in funct body
> 
> 
> > Consider two implementations of the same function:
> >
> > Implementation 1 (the old way):
> >
> > function num_listing (n : word) : ansistring;
> > var i : word;  num : string; result : ansistring;
> > begin
> >   result := '';
> >   for i :=  to n do begin
> > str (n, num);
> > result := result + num; end;
> >   num_listing := result;
> > end;
> >
> > Implementation 2 (possible because fpc permits nonrecursive 
> use of the 
> > function identifer):
> >
> > function num_listing (n : word) : ansistring;
> > var i : word;  num : string;
> > begin
> >   num_listing := '';
> >   for i :=  to n do begin
> > str (n, num);
> > num_listing := num_listing + num; end;
> > end;
> >
> > Which performs better under fpc?  In other words, do we incur a 
> > performance penalty in #2 for the nonrecursive use of the function 
> > identifier, particularly in a tight loop as shown?  Or does the 
> > additional variable and additional assignment at the end of 
> #1 make it 
> > the loser?  I know I could run a test, but I want to hear 
> the wisdom 
> > of the compiler writers.  Thanks.
> 
> The #2 is faster. There is no penalty for the use of the 
> function identifier.
> 
> 
> 
> 
> ___
> fpc-pascal maillist  -  [EMAIL PROTECTED] 
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
> 


___
fpc-pascal maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


RE: [fpc-pascal]use of funct identifier in funct body

2003-09-03 Thread Peter Vreman
> If i know good, the result variable exists in function without declare it.
> Use result instead function name.

That is correct. But the result keyword is only supported in Delphi and
ObjFpc modes




___
fpc-pascal maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal]IPC Question

2003-09-03 Thread Michael Weinert
Hi all,

I wrote 2 programs which are using the IPC queue. Now I have a
problem, that often the the queue cannot be opened.
I did some tests and cannot find out where the problem is.
The relevant code is here:

  ipcqueue:='/var/ipc';
  IPC_Key:=ftok(ipcqueue,'M');  // Eindeutigen Schlüsssel generieren
  IPC_ID:=msgget(IPC_Key,IPC_CREAT or 438); // Schnittstelle erstellen

No matter what I do with /var/ipc the IPC-Queue doesn't get created.
I tried /var/ipc as file, directory and not existent, but nothing helps.

Does anybody here know the right procedure to open an ipc-queue. Thanks
in advance for your help.

Michael.


-- 


 SysQuadrat
Michael Weinert Stuttgart Filderstadt-Plattenhardt
  Tel.: 0711-9970288 Fax: 5360559 Mobil: 0170-4141273
   http://www.linux-firewall.de  [EMAIL PROTECTED]


___
fpc-pascal maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal]IPC Question

2003-09-03 Thread L D Blake
Hello,
This is in reply to your letter of September 3, 2003


> Hi all,

> I wrote 2 programs which are using the IPC queue. Now I have a
> problem, that often the the queue cannot be opened.
> I did some tests and cannot find out where the problem is.
> The relevant code is here:

>   ipcqueue:='/var/ipc';
>   IPC_Key:=ftok(ipcqueue,'M');  // Eindeutigen Schlüsssel generieren
>   IPC_ID:=msgget(IPC_Key,IPC_CREAT or 438); // Schnittstelle erstellen

> No matter what I do with /var/ipc the IPC-Queue doesn't get created.
> I tried /var/ipc as file, directory and not existent, but nothing helps.

> Does anybody here know the right procedure to open an ipc-queue. Thanks
> in advance for your help.

> Michael.

When I first started with FP I ran into a bunch of really strange behaviour.
Files that wouldn't open, garbage printed in edit boxes, things being saved
under garbled filenames etc.

In my case, which may or may not apply to what you are doing here, the problem
was the difference between the way Pascal and Windows handle strings.  In
pascal a string is like this:



In windows (and I think Linux) it's like this:

<0>

If 'ipcqueue' is declared as type "string" could it be that your OS is seeing
the length byte as an error and failing to open the queue?  (At least that's
what happened to me in win32).

The fix, for me, was to write a small unit to translate back and forth between
Pascal and Null Terminated strings.

-- 
Best regards,
 L D Blake  


___
fpc-pascal maillist  -  [EMAIL PROTECTED]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal