Sunday, November 13, 2022

Digest for comp.lang.c++@googlegroups.com - 14 updates in 4 topics

"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Nov 13 12:56PM -0800

On 5/12/2022 12:16 PM, Chris M. Thomasson wrote:
> Using my experimental vector field to generate a fractal formation. Here
> is generation two:
 
> https://fractalforums.org/gallery/1612-120522191048.png
 
I call this one, BioLace:
 
https://fractalforums.org/gallery/1612-131122205452.png
 
All in C++.
aotto1968 <aotto1968@t-online.de>: Nov 13 09:56AM +0100

Hi, the following code failed to compile on Create
 
error: no matching function for call to 'ccmqmsgque::MqMsgqueCallbackC::MqMsgqueCallbackC(const
ccmqmsgque::MqMsgqueCallbackC::MqMsgqueCallbackU&)'
 
namespace ccmqmsgque {
struct MqMsgqueCallbackC {
enum MqMsgqueCallbackE {
PC_CallbackF,
PC_StaticCallbackF,
PC_IService,
PC_IEvent,
PC_IServerSetup,
PC_IServerCleanup,
PC_IBgError
} type;
 
union MqMsgqueCallbackU {
MqContextC::CallbackF Callback;
MqContextC::StaticCallbackF StaticCallback;
IService * Service;
IEvent * Event;
IServerSetup * ServerSetup;
IServerCleanup * ServerCleanup;
IBgError * BgError;
} call;
 
public:
MqMsgqueCallbackC(MqContextC::CallbackF const callback);
MqMsgqueCallbackC(MqContextC::StaticCallbackF const callback);
MqMsgqueCallbackC(IService * const service);
 
MqMsgqueCallbackC(IEvent * const event);
MqMsgqueCallbackC(IServerSetup * const serverSetup);
MqMsgqueCallbackC(IServerCleanup * const serverCleanup);
MqMsgqueCallbackC(IBgError * const bgError);
 
MqMsgqueCallbackC(MQ_CTX const context, MqMsgqueCallbackC* const copy);
 
static MK_CBP Create(const union MqMsgqueCallbackU& callback) {
return (MK_CBP) new MqMsgqueCallbackC(callback);
}
 
static enum MkErrorE Call ( MQ_CALLBACK_SERVICE_CALL_ARGS );
static void Free ( MQ_RT_ARGS MQ_CTX const context, MK_PTR *dataP);
static void Copy ( MQ_RT_ARGS MQ_CTX const context, MK_PTR *dataP);
};
};
 
 
Problem
 
1. I have a union with all possible argument-types and a CTOR for each type
2. Now I want to have a static "Create" function to call the CTOR for each type
3. I know I could write !! 7 !! "Create", just one for every type BUT I want to
use the union
 
Question, how I do it?
 
 
mfg
AO
Bonita Montero <Bonita.Montero@gmail.com>: Nov 13 11:05AM +0100

I'v not completely checked your code, but I guess you need a variant<>.
 
Am 13.11.2022 um 09:56 schrieb aotto1968:
Marcel Mueller <news.5.maazl@spamgourmet.org>: Nov 13 12:48PM +0100

Am 13.11.22 um 09:56 schrieb aotto1968:
> Problem
 
> 1. I have a union with all possible argument-types and a CTOR for each type
 
It seems that you are looking for boost::variant.
 
> 3. I know I could write !! 7 !! "Create", just one for every type BUT I
> want to
>    use the union
 
If you want a static Create function that takes your union instead of
the different types you should just invoke the copy constructor. Of
course you have to define one for the union.
 
Another option is to use a template argument type for Create. Then the
compiler creates the functions for you.
 
However, I see no use for the static Create over using operator new
directly at all.
 
 
Marcel
Michael S <already5chosen@yahoo.com>: Nov 13 04:28AM -0800

On Sunday, November 13, 2022 at 10:56:58 AM UTC+2, aotto1968 wrote:
 
> Question, how I do it?
 
> mfg
> AO
 
Compiler errors aside, your code does not make sense.
 
You probably want something like:
 
static MK_CBP Create(const union MqMsgqueCallbackU& callback, int createType) {
switch (createType) {
case PC_CallbackF:
return (MK_CBP) new MqMsgqueCallbackC(callback.Callback);
case PC_StaticCallbackF:
return (MK_CBP) new MqMsgqueCallbackC(callback.StaticCallback);
case PC_IService:
return (MK_CBP) new MqMsgqueCallbackC(callback.Service);
etc...
}
}
Michael S <already5chosen@yahoo.com>: Nov 13 04:44AM -0800

On Sunday, November 13, 2022 at 1:48:17 PM UTC+2, Marcel Mueller wrote:
> compiler creates the functions for you.
 
> However, I see no use for the static Create over using operator new
> directly at all.
 
That's correct.
But it would be better yet if class has just one trivial constructor
with no arguments plus several functions InitializeXXX() with similar
but non-identical names that do actual initialization.
Static polymorphism considered harmful and should be avoided as much
as possible. And static polymorphism through overloaded constructors
is one of the worst forms of static polymorphism, very confusing for
people that try to follow the code years or months later.
 
Bonita Montero <Bonita.Montero@gmail.com>: Nov 13 07:52PM +0100

Am 13.11.2022 um 12:48 schrieb Marcel Mueller:
 
>> 1. I have a union with all possible argument-types and a CTOR for each
>> type
 
> It seems that you are looking for boost::variant.
 
Why boost ? C++17 has also variant<>.
Andrey Tarasevich <andreytarasevich@hotmail.com>: Nov 13 11:39AM -0800

On 11/13/2022 12:56 AM, aotto1968 wrote:
 
> error: no matching function for call to
> 'ccmqmsgque::MqMsgqueCallbackC::MqMsgqueCallbackC(const
> ccmqmsgque::MqMsgqueCallbackC::MqMsgqueCallbackU&)'
 
So? You don't have a conversion from `MqMsgqueCallbackU` to
`MqMsgqueCallbackC`. Naturally, the code does not compile.
 
And how do you expect this conversion to work, if you supply
`MqMsgqueCallbackU` only? The supplied `callback` goes into your `call`
field. But what about `type` field? You can't determine `type` by
`MqMsgqueCallbackU` alone. It is not possible to determine which member
of an union is currently "active".
 
--
Best regards,
Andrey
Siri Cruise <chine.bleu@yahoo.com>: Nov 12 03:47PM -0700

In article <tknieo$36gkg$2@newsreader4.netcologne.de>,
 
> Lynn McGuire <lynnmcguire5@gmail.com> schrieb:
> > xkcd: Y2K
 
That's Y2K38.
 
 
> The switchover to 64-bit systems should have done this. Not sure
> that this cost a trillion dollars, but computers usually have a
> limited lifetime, so they had to be replaced anyway.
 
The problem is the all the archival formats that knew 32 bit
would always be enough.
 
--
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted. @
'I desire mercy, not sacrifice.' /|\
Discordia: not just a religion but also a parody. This post / \
I am an Andrea Chen sockpuppet. insults Islam. Mohammed
Siri Cruise <chine.bleu@yahoo.com>: Nov 12 03:49PM -0700

In article <tko9lc$168q6$1@dont-email.me>,
> boost xtime used to have 'long' counters, which indeed are 64-bit in
> some 64-bit implementations, but not so in others. Not sure about their
> current state, I have phased boost::xtime out in preparation for Y2038.
 
I use double which gives me subsecond resolution for millions of
years.
 
--
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted. @
'I desire mercy, not sacrifice.' /|\
Discordia: not just a religion but also a parody. This post / \
I am an Andrea Chen sockpuppet. insults Islam. Mohammed
Keith Thompson <Keith.S.Thompson+u@gmail.com>: Nov 12 06:00PM -0800

> on it. An unsigned 32 bit integer only gets us to 2106.
> https://en.wikipedia.org/wiki/Year_2038_problem
 
> Porting software to 64 bit is a tremendous work for most software.
 
An unsigned time_t makes it impossible to represent times before 1970.
Not all software is going to care about that, but in my opinion it's
an unacceptable price.
 
There are still 32-bit systems and environments. On my 64-bit Ubuntu
system I can compile with `gcc -m32` and get 32-bit pointers and time_t.
 
But since C and C++ require support for 64-bit integers anyway, it
should be practical to require 64-bit time_t even on 32-bit systems.
(Not sure about Fortran.)
 
The real problem is going to be 32-bit (or smaller) embedded systems
whose software can't be updated. On the other hand, a lot of such
systems probably don't care what time it is.
 
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for XCOM Labs
void Void(void) { Void(); } /* The recursive call of the void */
Klaus Wacker <klaus.w.wacker@t-online.de>: Nov 13 12:45PM


> Explained at:
> https://www.explainxkcd.com/wiki/index.php/2697:_Y2K_and_2038
 
> Lynn
 
My contribution to the 2038 problem:
 
----- o< ---------------------------------------------------
program p2038
! (c) Klaus Wacker
use datesub, only: jd,cdate
implicit none
integer, parameter :: minute=60
integer, parameter :: hour=60*minute
integer, parameter :: day=24*hour
integer, parameter :: maxepoch=(2**30-1)+2**30
integer date_time(8), jdmax, jdnow,jd1970,yyyy,mm,dd
integer secsmax,hoursmax,minsmax,yyyymax,mmmax,ddmax,daysub
integer monthstil
integer until(6)
integer i,ia,is,cnt
character*12 arg,lang
logical test,verbose
character*8, pointer :: texte(:,:)
character*8, target :: de_texte(2,9) = reshape( ['Jahr ','Jahre ','Monat ',&
&'Monate ', 'Tag ','Tage ','Stunde ','Stunden ','Minute ','Minuten ',&
&'Sekunde ','Sekunden','Noch ',' ',' und ',', ','Ende: ',&
&' '], shape(de_texte))
character*8, target :: en_texte(2,9) = reshape( ['year ','years ','month ',&
&'months ', 'day ','days ','hour ','hours ','minute ','minutes ',&
&'second ','seconds ',' ','left ',' and ',', ','The end:',&
&' '], shape(en_texte))
character*5 between
!
test=.false.
verbose=.false.
jd1970=jd(1970,1,1)
call date_and_time(values=date_time)
i=0
do ia=1,iargc()
call getarg(ia,arg)
if(arg.eq."-t") then
test=.true.
else if(arg.eq."-v") then
verbose=.true.
else
! numerical command line values override corresponding date_time values
i=i+1
read(arg,*,err=99) date_time(i)
endif
enddo
!
call getenv("LANG",lang)
if(test) write(*,*) "LANG=",lang
if(lang(1:2)=="de") then
texte => de_texte
else
texte => en_texte
endif
!
jdnow=jd(date_time(1),date_time(2),date_time(3))
if(test) write(*,*) date_time
jdmax=maxepoch/day+jd1970
secsmax=mod(maxepoch,day)
call hms(hoursmax,minsmax,secsmax)
call cdate(jdmax,yyyymax,mmmax,ddmax)
if(verbose) write(*,'(a,i4.4,a,i2.2,a,i2.2,a,i2.2,a,i2.2,a,i2.2,a)') &
&trim(texte(1,9))//" ",&
&yyyymax,"-",mmmax,"-",ddmax,"-",hoursmax,":",minsmax,":",secsmax," UTC"
until(3)=jdmax-jdnow
until(6)=(jdnow-jd1970)*day - date_time(4)*minute &
& + date_time(5)*hour + date_time(6)*minute + date_time(7)
! this should be the same as $(date +%s)
if(test) write(*,*) until(6)
until(6) = maxepoch - until(6) - until(3)*day
daysub = 0
if(until(6)<0) then
daysub = 1
until(6) = until(6)+day
endif
call hms(until(4),until(5),until(6))
until(1) = yyyymax-date_time(1)
until(3) = jdmax - jd(date_time(1)+until(1),date_time(2),date_time(3)) - daysub
if(until(3)<0) then
until(1) = until(1)-1
! until(3) = jdmax - jd(date_time(1)+until(1),date_time(2),date_time(3)) - daysub
endif
! until(2) cannot be a do variable
do monthstil=11,0,-1
until(3) = jdmax - jd(date_time(1)+until(1) + (date_time(2)+monthstil-1)/12,&
&mod(date_time(2)+monthstil-1,12)+1,date_time(3)) - daysub
if(until(3)>=0) exit
enddo
until(2)=monthstil
cnt = count(until>0)
if(texte(1,7)/=" ") write(*,'(a)',advance="no") trim(texte(1,7))//" "
do i=1,6
if(cnt==2) then
between=texte(1,8)
elseif(cnt==1) then
between=""
else
between=texte(2,8)
endif
if(until(i)/=0) then
is=min(until(i),2)
write(*,'(i0,a)',advance="no") until(i)," "//trim(texte(is,i))//trim(between)//" "
cnt=cnt-1
endif
enddo
write(*,'(a)') trim(texte(2,7))
stop
!
99 write(*,*) "Invalid argument ",ia,": ",arg
stop 1
!
contains
subroutine hms(hours,mins,secs)
implicit none
integer, intent(inout) :: secs
integer, intent(out) :: hours,mins
hours=secs/hour
secs=mod(secs,hour)
mins=secs/minute
secs=mod(secs,minute)
end subroutine hms
end program p2038
----- o< ---------------------------------------------------
 
DATESUB is a piece of software that I got really long time ago via
this newsgroup (with some trivial cahnges in lowercase, mainly to turn
it into a module):
 
 
----- o< ---------------------------------------------------
module datesub
contains
SUBROUTINE CALEND(YYYY,DDD,MM,DD)
!=============CALEND WHEN GIVEN A VALID YEAR, YYYY, AND DAY OF THE
! YEAR, DDD, RETURNS THE MONTH, MM, AND DAY OF THE
! MONTH, DD.
! SEE ACM ALGORITHM 398, TABLELESS DATE CONVERSION, BY
! DICK STONE, CACM 13(10):621.
implicit none
INTEGER YYYY,DDD,MM,DD,T
T=0
IF(MOD(YYYY,4).EQ.0) T=1
!-----------THE FOLLOWING STATEMENT IS NECESSARY IF YYYY IS LESS TNAN
! 1900 OR GREATER THAN 2100.
IF(MOD(YYYY,400).NE.0.AND.MOD(YYYY,100).EQ.0) T=0
DD=DDD
IF(DDD.GT.59+T) DD=DD+2-T
MM=((DD+91)*100)/3055
DD=(DD+91)-(MM*3055)/100
MM=MM-2
!----------MM WILL BE CORRECT IFF DDD IS CORRECT FOR YYYY.
IF(MM.GE.1 .AND. MM.LE.12) RETURN
WRITE(*,1) DDD
1 FORMAT('0$$$CALEND: DAY OF THE YEAR INPUT =',I11,' IS OUT OF RANGE.')
STOP
END SUBROUTINE
SUBROUTINE CDATE(JD,YYYY,MM,DD)
!=======GIVEN A JULIAN DAY NUMBER, NNNNNNNN, YYYY,MM,DD ARE RETURNED AS
! AS THE CALENDAR DATE. JD=NNNNNNNN IS THE JULIAN DATE
! FROM AN EPOCK IN THE VERY DISTANT PAST. SEE CACM
! 1968 11(10):657, LETTER TO THE EDITOR BY FLIEGEL AND
! VAN FLANDERN.
! EXAMPLE CALL CDATE(2440588,YYYY,MM,DD) RETURNS 1970 1 1 .
!
implicit none
INTEGER JD,YYYY,MM,DD,L,N
L=JD+68569
N=4*L/146097
L=L-(146097*N + 3)/4
YYYY=4000*(L+1)/1461001
L=L-1461*YYYY/4+31
MM=80*L/2447
DD=L-2447*MM/80
L=MM/11
MM=MM + 2 - 12*L
YYYY=100*(N-49) + YYYY + L
RETURN
END SUBROUTINE CDATE
SUBROUTINE DAYSUB(JD,YYYY,MM,DD,WD,DDD)
!========GIVEN JD, A JULIAN DAY # (SEE ASF JD), THIS ROUTINE
! CALCULATES DD, THE DAY NUMBER OF THE MONTH; MM, THE MONTH
! NUMBER; YYYY THE YEAR; WD THE WEEKDAY NUMBER, AND DDD
! THE DAY NUMBER OF THE YEAR.
! ARITHMETIC STATEMENT FUNCTIONS 'IZLR' AND 'IDAY' ARE TAKEN
! FROM REMARK ON ALGORITHM 398, BY J. DOUGLAS ROBERTSON,
! CACM 15(10):918.
!
! EXAMPLE: CALL DAYSUB(2440588,YYYY,MM,DD,WD,DDD) YIELDS 1970 1 1 4 1.
!
implicit none
INTEGER JD,YYYY,MM,DD,WD,DDD
integer iday,izlr
!
!------IZLR(YYYY,MM,DD) GIVES THE WEEKDAY NUMBER 0=SUNDAY, 1=MONDAY,
! ... 6=SATURDAY. EXAMPLE: IZLR(1970,1,1)=4=THURSDAY
!
IZLR(YYYY,MM,DD)=MOD((13*(MM+10-(MM+10)/13*12)-1)/5+DD+77 &
+5*(YYYY+(MM-14)/12-(YYYY+(MM-14)/12)/100*100)/4 &
+ (YYYY+(MM-14)/12)/400-(YYYY+(MM-14)/12)/100*2,7)
!
!------IDAY IS A COMPANION TO CALEND; GIVEN A CALENDAR DATE, YYYY, MM,
! DD, IDAY IS RETURNED AS THE DAY OF THE YEAR.
! EXAMPLE: IDAY(1984,4,22)=113
!
IDAY(YYYY,MM,DD)=3055*(MM+2)/100-(MM+10)/13*2-91 &
+(1-(MOD(YYYY,4)+3)/4+(MOD(YYYY,100)+99)/100 &
-(MOD(YYYY,400)+399)/400)*(MM+10)/13+DD
!
CALL CDATE(JD,YYYY,MM,DD)
WD=IZLR(YYYY,MM,DD)
DDD=IDAY(YYYY,MM,DD)
RETURN
END SUBROUTINE DAYSUB
FUNCTION JD(YYYY,MM,DD)
implicit none
integer jd
INTEGER YYYY,MM,DD
! DATE ROUTINE JD(YYYY,MM,DD) CONVERTS CALENDER DATE TO
! JULIAN DATE. SEE CACM 1968 11(10):657, LETTER TO THE
! EDITOR BY HENRY F. FLIEGEL AND THOMAS C. VAN FLANDERN.
! EXAMPLE JD(1970,1,1)=2440588
JD=DD-32075+1461*(YYYY+4800+(MM-14)/12)/4 &
+367*(MM-2-((MM-14)/12)*12)/12-3* &
((YYYY+4900+(MM-14)/12)/100)/4
RETURN
END FUNCTION JD
FUNCTION NDAYS(MM1,DD1,YYYY1, MM2,DD2,YYYY2)
implicit none
integer ndays
INTEGER YYYY1,MM1,DD1,YYYY2,MM2,DD2
!==============NDAYS IS RETURNED AS THE NUMBER OF DAYS BETWEEN TWO
! DATES; THAT IS MM1/DD1/YYYY1 MINUS MM2/DD2/YYYY2,
! WHERE DATEI AND DATEJ HAVE ELEMENTS MM, DD, YYYY.
!-------NDAYS WILL BE POSITIVE IFF DATE1 IS MORE RECENT THAN DATE2.
NDAYS=JD(YYYY1,MM1,DD1)-JD(YYYY2,MM2,DD2)
RETURN
END FUNCTION NDAYS
end module datesub
----- o< ---------------------------------------------------
 
 
 
 
--
Klaus Wacker klaus.w.wacker@t-online.de
51°29'7"N 7°25'7"E
red floyd <no.spam.here@its.invalid>: Nov 13 09:49AM -0800

On 11/12/2022 6:00 PM, Keith Thompson wrote:
> On the other hand, a lot of such
> systems probably don't care what time it is.
 
Why am I thinking of Chicago now?
Michael S <already5chosen@yahoo.com>: Nov 12 04:21PM -0800

On Wednesday, November 9, 2022 at 1:37:23 AM UTC+2, Michael S wrote:
 
> Most likely you had seen std::chrono::high_resolution_clock broken (and
> this one is broken indeed) and remembered that *something* is broken,
> but forgot what is broken and what not.
 
Elaboration and rectification:
Mingw64 std::chrono::high_resolution_clock is broken on Win7 and derivatives
like WS2008r2.
On Window 10 and derivatives (WS2016 and Ws2019) it works fine.
In particular, on the Ws2019 it works not just fine, but very well providing
100ns increments.
 
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: