J'ai installé Lazarus 1.6/FPC 3.0, 64 bits sur Windows 10 (64 bits) et le portage du code Delphi contenant la fonction InterlockedCompareExchangePointer
.FPC 3.0 et InterlockedCompareExchange
FPC 3.0 n'inclut pas la déclaration InterlockedCompareExchangePointer
; Au contraire, elle "surcharge" InterlockedCompareExchange
comme on peut le voir dans systemh.inc
:
function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint; public name 'FPC_INTERLOCKEDCOMPAREEXCHANGE';
{$ifdef cpu64}
function InterlockedCompareExchange64(var Target: int64; NewValue: int64; Comperand: int64): int64; public name 'FPC_INTERLOCKEDCOMPAREEXCHANGE64';
function InterlockedCompareExchange(var Target: Pointer; NewValue: Pointer; Comperand: Pointer): Pointer; external name 'FPC_INTERLOCKEDCOMPAREEXCHANGE64';
{$else cpu64}
function InterlockedCompareExchange(var Target: Pointer; NewValue: Pointer; Comperand: Pointer): Pointer; external name 'FPC_INTERLOCKEDCOMPAREEXCHANGE';
{$endif cpu64}
Maintenant, je suis en train d'utiliser InterlockedCompareExchange
avec des pointeurs:
program Project1;
uses Windows;
function Test: Boolean;
var
P1, P2: Pointer;
begin
Result:= InterlockedCompareExchange(P1, P2, nil) <> nil
end;
begin
Test;
end.
et il ne compilent pas avec le message
project1.lpr(10,50) Error: Incompatible type for arg no. 3: Got "Pointer", expected "LongInt"
si évidemment la "surcharge" ne fonctionne pas. Comment le réparer? J'utilise le FPC 3.0 64 bits sur la cible par défaut (64 bits).
Essayez d'utiliser la fonction '' InterlockedCompareExchangePointer' de jwawinbase' unité. Ou supprimez l'unité 'windows' de la clause' uses' ou appelez la fonction comme 'System.InterlockedCompareExchange' car il s'agit d'une plateforme croisée. – Abelisto
Ceux-ci devraient tous être des intrinsèques du compilateur dans un monde idéal –