Path: csiph.com!news.mixmin.net!news.albasani.net!.POSTED!not-for-mail From: Melzzzzz Newsgroups: comp.lang.c++ Subject: Re: This will work or not? Date: Mon, 5 Sep 2016 13:36:50 +0200 Organization: albasani.net Lines: 39 Message-ID: <20160905133650.798aaabb@maxa-pc> References: <20160831145918.45a0c396@maxa-pc> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net ISSpY4CnJsaQf9G9ULWv0N5cW2iO3/wwda9UJuAkCLRTAtdEl0pxKIkMHTNRk8QzO3Pz62HcvOrkywZaM7NwwA== NNTP-Posting-Date: Mon, 5 Sep 2016 11:36:50 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="BgOk0GQiDHMT5XPWsz7Nrxsv8s5hjz5MYR9LrrNkkDQpwEfS/ufCOp+lGwwMJHDWHq2Fit2MGWLl/WhWNqhhGbQjTSNU3Pv0eXBWq2pwg5NLdsraBNwhqb90KWkBAEcL"; mail-complaints-to="abuse@albasani.net" X-Newsreader: Claws Mail 3.14.0 (GTK+ 2.24.30; x86_64-unknown-linux-gnu) Cancel-Lock: sha1:vI7kgYd1a/T4vlniyr0VUXtFRok= Xref: csiph.com comp.lang.c++:44860 On Mon, 5 Sep 2016 11:34:05 +0000 (UTC) Juha Nieminen wrote: > Melzzzzz wrote: > > struct Problem{ > > uint32_t a; > > uint32_t b; > > uint64_t c; > > uint32_t d; > > bool check_it() { > > for (uint32_t* i = &a;i != &d; ++i) > > if (*i>0) return true; > > return false; > > } > > > > }; > > Rather than mess with implementation-defined and undefined behavior > trickery, just redesign your struct better, in a manner that allows > you to do what you want (ie. iterate through the member variables > in a loop) without compromising code quality and standard conforming. > > For example: > > struct Problem > { > std::uint32_t values[4]; > > std::uint32_t a() const { return values[0]; } > void a(std::uint32_t v) { values[0] = v; } > // and same for b(), c() and d(). > }; > > Now you can safely iterate through the values in a loop. > > --- news://freenews.netfront.net/ - complaints: news@netfront.net --- What about uint64_t ? It's a big struct I just made it minimal to show problem.