Re: C++ reinterpret_cast question
On 2020-01-30 6:35 AM, Charles Mills wrote: I suppose if someone REALLY wanted to be a C++ pedant, myStruct *opts_char = reinterpret_cast(reinterpret_cast(opts)); haha! that's what I would code but in reality a reinterpret_cast is a raw cast so it doesn't matter. It's a style thing so you can find casts using an IDE. -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: C++ reinterpret_cast question
lol. You might be a Programming Geek if "code still works" is a "side benefit". sas On Wed, Jan 29, 2020 at 5:35 PM Charles Mills wrote: > You're a genius! Thanks. Message is gone, and as a side benefit, the code > still works. -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: C++ reinterpret_cast question
Tried just a simple C-style cast (myStruct *)opts; No joy. For some reason extern "OS" * to struct * seems to require a two-stage cast. Charles -Original Message- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf Of Charles Mills Sent: Wednesday, January 29, 2020 2:36 PM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: C++ reinterpret_cast question You're a genius! Thanks. Message is gone, and as a side benefit, the code still works. I suppose if someone REALLY wanted to be a C++ pedant, myStruct *opts_char = reinterpret_cast(reinterpret_cast(opts)); I wonder how much of the problem is the extern "OS". On MS VS, where I edit and test compile, the extern "OS" is skipped by an #ifdef WIN32 and in that situation I get no warning (neither with the old code nor with your new code). Or perhaps reinterpret_cast is just fussy. I did not try simply = (myStruct *)opts; I might have tried that before posting. Charles -Original Message- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf Of Gord Tomlin Sent: Wednesday, January 29, 2020 11:42 AM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: C++ reinterpret_cast question On 2020-01-29 13:29, Charles Mills wrote: > If you're not a C++ person you may hit Delete at any time ... > > I want to load a module that is a non-executable table (and non-reentrant) > and then modify it. > > I have the entry point declared as > > extern "OS" typedef int compiler_t(void *parm1); > compiler_t *opts; > > (compiler_t is what is expected by several methods unrelated to this exact > question, and this all works, so I would like to leave that alone.) > > When I want to modify it I want to treat it as a struct. So I say > > myStruct *opts_char = reinterpret_cast(opts); > > That generates the following warning in XLC: > > CCN5216 (W) An expression of type "extern "OS" int (*)(void *)" cannot be > converted to type "myStruct *". -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: C++ reinterpret_cast question
You're a genius! Thanks. Message is gone, and as a side benefit, the code still works. I suppose if someone REALLY wanted to be a C++ pedant, myStruct *opts_char = reinterpret_cast(reinterpret_cast(opts)); I wonder how much of the problem is the extern "OS". On MS VS, where I edit and test compile, the extern "OS" is skipped by an #ifdef WIN32 and in that situation I get no warning (neither with the old code nor with your new code). Or perhaps reinterpret_cast is just fussy. I did not try simply = (myStruct *)opts; I might have tried that before posting. Charles -Original Message- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf Of Gord Tomlin Sent: Wednesday, January 29, 2020 11:42 AM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: C++ reinterpret_cast question On 2020-01-29 13:29, Charles Mills wrote: > If you're not a C++ person you may hit Delete at any time ... > > I want to load a module that is a non-executable table (and non-reentrant) > and then modify it. > > I have the entry point declared as > > extern "OS" typedef int compiler_t(void *parm1); > compiler_t *opts; > > (compiler_t is what is expected by several methods unrelated to this exact > question, and this all works, so I would like to leave that alone.) > > When I want to modify it I want to treat it as a struct. So I say > > myStruct *opts_char = reinterpret_cast(opts); > > That generates the following warning in XLC: > > CCN5216 (W) An expression of type "extern "OS" int (*)(void *)" cannot be > converted to type "myStruct *". > > > The code all works perfectly. I'd just like to get rid of the warning. > Anyone know what to do? > > Charles > > -- > For IBM-MAIN subscribe / signoff / archive access instructions, > send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN > I'm not in a position to test this right now, but does this work: myStruct *opts_char = reinterpret_cast((void *) opts); -- Regards, Gord Tomlin Action Software International (a division of Mazda Computer Corporation) Tel: (905) 470-7113, Fax: (905) 470-6507 Support: https://actionsoftware.com/support/ -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: C++ reinterpret_cast question
@Allan and @Joseph, I should have said that this as an intellectual exercise I want to write C++ that makes the warning go away, not a #pragma or similar that suppresses the message. Yes, I know that all casts are dangerous. A extern "OS" * is I believe always the address of an "old-fashioned" entry point. I use it for my assembler routines. I suspect it is safe to cast. In this case, it is an address filled in by LOAD, so it is certainly a module in memory, not a vftable. Charles -Original Message- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf Of Allan Kielstra Sent: Wednesday, January 29, 2020 12:27 PM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: C++ reinterpret_cast question Also, I trust that you know what you're doing! Depending on the implementation of C++, a pointer to a function can sometimes be a pointer to a function descriptor. So be careful with what you do with opts_char. (But you say that the resulting code basically works so that is good.) Also, on USS ahk> cat cm.C extern "OS" typedef int mytype(void *); extern mytype M; void p() { char *x; x = reinterpret_cast(M); } ahk> xlC -c cm.C "./cm.C", line 8.33: CCN5216 (W) An expression of type "extern "OS" int (*)(void *)" cannot be converted to type "char *". ahk> xlC -c -qsuppress=CCN5216 cm.C ahk> -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: C++ reinterpret_cast question
Hmmm. V2R2 Charles -Original Message- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf Of Allan Kielstra Sent: Wednesday, January 29, 2020 12:18 PM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: C++ reinterpret_cast question FWIW, you don't get this warning with 2.4.1 (or 2.3.1). What version are you using? -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: C++ reinterpret_cast question
Also, I trust that you know what you're doing! Depending on the implementation of C++, a pointer to a function can sometimes be a pointer to a function descriptor. So be careful with what you do with opts_char. (But you say that the resulting code basically works so that is good.) Also, on USS ahk> cat cm.C extern "OS" typedef int mytype(void *); extern mytype M; void p() { char *x; x = reinterpret_cast(M); } ahk> xlC -c cm.C "./cm.C", line 8.33: CCN5216 (W) An expression of type "extern "OS" int (*)(void *)" cannot be converted to type "char *". ahk> xlC -c -qsuppress=CCN5216 cm.C ahk> -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: C++ reinterpret_cast question
FWIW, you don't get this warning with 2.4.1 (or 2.3.1). What version are you using? -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: C++ reinterpret_cast question
Microsoft Visual C has #pragma warning (disable : ) dint know about XL C > On Jan 29, 2020, at 1:29 PM, Charles Mills wrote: > > If you're not a C++ person you may hit Delete at any time ... > > I want to load a module that is a non-executable table (and non-reentrant) > and then modify it. > > I have the entry point declared as > > extern "OS" typedef int compiler_t(void *parm1); > compiler_t *opts; > > (compiler_t is what is expected by several methods unrelated to this exact > question, and this all works, so I would like to leave that alone.) > > When I want to modify it I want to treat it as a struct. So I say > >myStruct *opts_char = reinterpret_cast(opts); > > That generates the following warning in XLC: > > CCN5216 (W) An expression of type "extern "OS" int (*)(void *)" cannot be > converted to type "myStruct *". > > > The code all works perfectly. I'd just like to get rid of the warning. > Anyone know what to do? > > Charles > > -- > For IBM-MAIN subscribe / signoff / archive access instructions, > send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
Re: C++ reinterpret_cast question
On 2020-01-29 13:29, Charles Mills wrote: If you're not a C++ person you may hit Delete at any time ... I want to load a module that is a non-executable table (and non-reentrant) and then modify it. I have the entry point declared as extern "OS" typedef int compiler_t(void *parm1); compiler_t *opts; (compiler_t is what is expected by several methods unrelated to this exact question, and this all works, so I would like to leave that alone.) When I want to modify it I want to treat it as a struct. So I say myStruct *opts_char = reinterpret_cast(opts); That generates the following warning in XLC: CCN5216 (W) An expression of type "extern "OS" int (*)(void *)" cannot be converted to type "myStruct *". The code all works perfectly. I'd just like to get rid of the warning. Anyone know what to do? Charles -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN I'm not in a position to test this right now, but does this work: myStruct *opts_char = reinterpret_cast((void *) opts); -- Regards, Gord Tomlin Action Software International (a division of Mazda Computer Corporation) Tel: (905) 470-7113, Fax: (905) 470-6507 Support: https://actionsoftware.com/support/ -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
C++ reinterpret_cast question
If you're not a C++ person you may hit Delete at any time ... I want to load a module that is a non-executable table (and non-reentrant) and then modify it. I have the entry point declared as extern "OS" typedef int compiler_t(void *parm1); compiler_t *opts; (compiler_t is what is expected by several methods unrelated to this exact question, and this all works, so I would like to leave that alone.) When I want to modify it I want to treat it as a struct. So I say myStruct *opts_char = reinterpret_cast(opts); That generates the following warning in XLC: CCN5216 (W) An expression of type "extern "OS" int (*)(void *)" cannot be converted to type "myStruct *". The code all works perfectly. I'd just like to get rid of the warning. Anyone know what to do? Charles -- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN