QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: EricE on March 25, 2020, 05:26:22 pm

Title: Calling the cpp function time
Post by: EricE on March 25, 2020, 05:26:22 pm
The cpp time function gets the number of seconds since 00:00 hours, Jan 1, 1970 UTC.
http://www.cplusplus.com/reference/ctime/time/?kw=time (http://www.cplusplus.com/reference/ctime/time/?kw=time)

The function prototype is:
time_t time (time_t* timer);

According to the QB64 documentation for Using _OFFSET,
http://www.qb64.org/wiki/Using_OFFSET (http://www.qb64.org/wiki/Using_OFFSET)
we should be able to call the time function in QB64 by declaring it as:
Code: QB64: [Select]

Compiling this test program fails. What am I doing wrong?

Code: QB64: [Select]
  1.     FUNCTION time&& (BYVAL TimerPtr AS _UNSIGNED _OFFSET)
  2.  
  3. DIM time_now1&&
  4. DIM time_now2&&
  5.  
  6. time_now1&& = time&&(_OFFSET(time_now2&&))
  7.  
  8. PRINT time_now1&&
  9. PRINT time_now2&&
  10.  
Title: Re: Calling the cpp function time
Post by: Dav on March 25, 2020, 06:15:41 pm
I changed it to DECLARE CUSTOMTYPE LIBRARY and it compiled and ran.  I'm not a cpp dude, so I don't know if the info it gave is correct.  But it compiled after that change.

- Dav
Title: Re: Calling the cpp function time
Post by: EricE on March 25, 2020, 06:40:45 pm
Thank you Dav, it does indeed work now.
I wonder how I missed using CUSTOMTYPE in the documentation?
Actually, what does CUSTOMTYPE do?

The time value returned looks correct.
Here is a website that will give the unix time stamp for comparison.
https://www.unixtimestamp.com (https://www.unixtimestamp.com)

Code: QB64: [Select]
  1.     FUNCTION time&& (BYVAL TimerPtr AS _UNSIGNED _OFFSET)
  2.  
  3. DIM time_now1&&
  4. DIM time_now2&&
  5.  
  6. time_now1&& = time&&(_OFFSET(time_now2&&))
  7.  
  8. PRINT time_now1&&
  9. PRINT time_now2&&
Title: Re: Calling the cpp function time
Post by: EricE on March 25, 2020, 06:52:38 pm
Found this comment in the release notes for QB64 v0.94.

Quote
-DECLARE CUSTOMTYPE LIBRARY, allows you to override the required types and use the variable types you want, provided they are the same size

This makes sense as the compiler error messages that were being raised indicated an incompatibility between the time&& declared parameter type and the cpp type "time_t".