Author Topic: Calling the cpp function time  (Read 3023 times)

0 Members and 1 Guest are viewing this topic.

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Calling the cpp function time
« 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

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
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.  

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Calling the cpp function time
« Reply #1 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

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: Calling the cpp function time
« Reply #2 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

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&&
« Last Edit: March 25, 2020, 07:24:38 pm by EricE »

Offline EricE

  • Forum Regular
  • Posts: 114
    • View Profile
Re: Calling the cpp function time
« Reply #3 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".
« Last Edit: March 25, 2020, 06:59:11 pm by EricE »