Search code examples
cdelphitypeconverter

Convert c time function delphi


C code looks like this;

clock_t clock_start, clock_end;

      clock_start = clock();

      if ((pass = create_pass(100, time(NULL))) == NULL)
         crate_pass_err("passerror");

What exactly is time here?

I do with delphi;

function create_pass(sz:DWORD;Sd:DWORD):Pointer;stdcall;external DLL;

start:=gettickcount;
DecodeTime(now, hours, mins, secs, milliSecs);
timeread:= strtoint(FormatDateTime('NNSSZZZ',time));

    pass:=create_pass(100,timeread); // timeread or millisecs or start ?

Which of these will give the same result? Or is there another solution?

edit: The results I get in the program output are not exactly the same. What exactly is "time" doing in c code? I am trying to find it. ( output of c code : "stacksample" , output of delphi code "%Oê^%O" I'm trying to convert my password program to Delphi )


Solution

  • time() is a C function that usually returns the number of seconds that have elapsed since the Unix epoch, January 1 1970 00:00 UTC (I say usually because the value actually returned by time() is not mandated by the C standard, but most implementations are done this way).

    A Delphi translation of the C code you have shown would look something like this:

    uses
      ..., DateUtils;
    
    var
      clock_start, clock_end: DWORD;
    begin
      ...
      clock_start := GetTickCount;
      pass := create_pass(100, DWORD(DateTimeToUnix(Now, False)));
      if (pass = nil) then
        crate_pass_err('passerror');
      ...
      clock_end := GetTickCount;
      ...
    end;