Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #71327

Re: How to "fake" a member initialization?

From Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt>
Newsgroups comp.lang.c++
Subject Re: How to "fake" a member initialization?
Date 2020-01-14 01:04 +0000
Organization Aioe.org NNTP Server
Message-ID <qvj43e$dia$1@gioia.aioe.org> (permalink)
References <qvieas$1dah$1@gioia.aioe.org> <qvik43$8ki$1@gioia.aioe.org> <slrnr1pl5h.km3.grahn+nntp@frailea.sa.invalid> <qvilns$fml$1@gioia.aioe.org> <slrnr1pp7i.km3.grahn+nntp@frailea.sa.invalid>

Show all headers | View raw


Às 21:45 de 13/01/20, Jorgen Grahn escreveu:
> On Mon, 2020-01-13, Paulo da Silva wrote:
...

>>>>
>>>> From the answers so far, may be I didn't explain my problem very well :(
>>>
>>> What was wrong with my answer?
>>>
>> Sorry, I hadn't seen your answer when I posted.
> 
> Come to think of it, I posted it only 20--30 minutes before you posted
> so I shouldn't have assumed you had.
> 
Yes, I needed to leave the computer for a while when responding.

>> Now that I have read it ...
>>
>> About the compiler: It's g++ and all options are appropriate for the
>> rest of the project.
> 
> I must assume that means "it's at work, so I cannot disclose that
> information".
No, but this is a moderate sized project, not new, and I want to keep
those warnings, if there are members uninitialized, except for special
cases like this.

> ...

>> I have this code:
>> Dir::Dir(): cur_entryp(0),vec(0)
>> {
>> 	// memset((void *)&cur_dev,0,sizeof(cur_dev)); // OK
>> 	// memset((void *)&cur_dev,0,0); // OK and do nothing.
> 
> I strongly dislike the first two -- they bring in C style thinking,
> and would happily and silently trash cur_dev if it ever got a real
> constructor.
So do I. That's the main reason why I asked for suggestions.

> 
>> 	cur_dev={}; // OK
>>
>> 	... other init stuff ...
>>
>> }
>>
>> The member I am talking about is cur_dev.
>> cur_dev={} also works (no warning)!
>> Does this cause any code to be executed?
>> Is it the best way in c++?
> 

> Personally, I think it's fine to have uninitialized members[0], and
> the only good solution I can see is to change the compiler options.
> But if you cannot make that decision, I think you should go to whoever
> makes those decisions and ask "well, how do you want me to handle this
> situation, then"?
Of course I could just ignore the warning, but I became curious on how
to "clean" just this one. I also like clean compilations.

Thanks.

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to "fake" a member initialization? Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> - 2020-01-13 18:53 +0000
  Re: How to "fake" a member initialization? Öö Tiib <ootiib@hot.ee> - 2020-01-13 11:08 -0800
  Re: How to "fake" a member initialization? Bonita Montero <Bonita.Montero@gmail.com> - 2020-01-13 20:12 +0100
  Re: How to "fake" a member initialization? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-01-13 20:15 +0000
  Re: How to "fake" a member initialization? Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> - 2020-01-13 20:32 +0000
    Re: How to "fake" a member initialization? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-01-13 20:36 +0000
      Re: How to "fake" a member initialization? Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> - 2020-01-13 20:59 +0000
        Re: How to "fake" a member initialization? Melzzzzz <Melzzzzz@zzzzz.com> - 2020-01-13 21:29 +0000
        Re: How to "fake" a member initialization? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-01-13 21:45 +0000
          Re: How to "fake" a member initialization? Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> - 2020-01-14 01:04 +0000
    Re: How to "fake" a member initialization? Melzzzzz <Melzzzzz@zzzzz.com> - 2020-01-13 21:28 +0000
  Re: How to "fake" a member initialization? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2020-01-13 23:23 +0100
  Re: How to "fake" a member initialization? Frederick Gotham <cauldwell.thomas@gmail.com> - 2020-01-14 00:34 -0800
    Re: How to "fake" a member initialization? Paulo da Silva <p_s_d_a_s_i_l_v_a_ns@netcabo.pt> - 2020-01-14 15:33 +0000

csiph-web