Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #128927
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Allocate variables within code blocks. |
| Date | 2018-04-08 12:29 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <87bmeu7x7b.fsf@bsb.me.uk> (permalink) |
| References | <pacshc$18uv$1@gioia.aioe.org> |
"itsme.susila" <itsme.susila@gmx.com> writes:
> Allocate variables within code blocks
>
> Within a function, I will have many for loops:
I'd reconsider that design if I were you. I suppose it depends on what
the program is, but short single-purpose function generally make for
better code.
> [code]
> void myfn(){
> int, x, y, z;
> for (i = 0,...){
> u64 u, v, w;
>
> u = 3;
> x = u * 6;
> ......
>
>
> }
>
>
> return;
> }
> [/code]
>
> Which is the better practice (giving faster codes):
> Should I allocate u,v,w at the start of myfn(); I know beforehand they
> would be used many times over.
Modern compilers will generate good code in both cases. It's almost
always better to write for clarity rather than generated code. Once you
have a clear program, measure the performance to see what parts are
taking up the time.
--
Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
Allocate variables within code blocks. "itsme.susila" <itsme.susila@gmx.com> - 2018-04-08 18:56 +0800
Re: Allocate variables within code blocks. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-04-08 12:29 +0100
Re: Allocate variables within code blocks. Steven Petruzzellis <frelwizzen@gmail.com> - 2018-04-08 05:06 -0700
Re: Allocate variables within code blocks. Spiros Bousbouras <spibou@gmail.com> - 2018-04-08 13:00 +0000
Re: Allocate variables within code blocks. Steven Petruzzellis <frelwizzen@gmail.com> - 2018-04-08 08:14 -0700
Re: Allocate variables within code blocks. GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-04-08 16:37 +0200
Re: Allocate variables within code blocks. Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-04-08 08:53 -0600
Re: Allocate variables within code blocks. bartc <bc@freeuk.com> - 2018-04-08 16:32 +0100
Re: Allocate variables within code blocks. Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-04-08 15:19 -0600
Re: Allocate variables within code blocks. Tim Rentsch <txr@alumni.caltech.edu> - 2018-04-09 07:59 -0700
Re: Allocate variables within code blocks. Tim Rentsch <txr@alumni.caltech.edu> - 2018-04-11 06:29 -0700
Re: Allocate variables within code blocks. bartc <bc@freeuk.com> - 2018-04-11 15:58 +0100
Re: Allocate variables within code blocks. Tim Rentsch <txr@alumni.caltech.edu> - 2018-04-11 11:28 -0700
Re: Allocate variables within code blocks. Steven Petruzzellis <frelwizzen@gmail.com> - 2018-04-13 00:42 -0700
Re: Allocate variables within code blocks. Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-04-11 10:25 +0000
Re: Allocate variables within code blocks. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-04-08 19:27 +0100
Re: Allocate variables within code blocks. James Kuyper <jameskuyper@verizon.net> - 2018-04-08 07:54 -0400
Re: Allocate variables within code blocks. Spiros Bousbouras <spibou@gmail.com> - 2018-04-08 12:50 +0000
Re: Allocate variables within code blocks. bartc <bc@freeuk.com> - 2018-04-08 13:42 +0100
Re: Allocate variables within code blocks. "itsme.susila" <itsme.susila@gmx.com> - 2018-04-08 22:19 +0800
Re: Allocate variables within code blocks. "itsme.susila" <itsme.susila@gmx.com> - 2018-04-08 22:27 +0800
Re: Allocate variables within code blocks. Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2018-04-08 10:42 -0400
Re: Allocate variables within code blocks. bartc <bc@freeuk.com> - 2018-04-08 15:37 +0100
Re: Allocate variables within code blocks. David Brown <david.brown@hesbynett.no> - 2018-04-08 16:45 +0200
Re: Allocate variables within code blocks. "itsme.susila" <itsme.susila@gmx.com> - 2018-04-08 22:55 +0800
Re: Allocate variables within code blocks. GOTHIER Nathan <nathan.gothier@gmail.com> - 2018-04-08 17:52 +0200
Re: Allocate variables within code blocks. Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-04-08 09:00 -0600
Re: Allocate variables within code blocks. Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-04-08 08:51 -0600
Re: Allocate variables within code blocks. Tim Rentsch <txr@alumni.caltech.edu> - 2018-04-08 15:59 -0700
Re: Allocate variables within code blocks. "itsme.susila" <itsme.susila@gmx.com> - 2018-04-09 11:54 +0800
Re: Allocate variables within code blocks. David Brown <david.brown@hesbynett.no> - 2018-04-09 09:31 +0200
Re: Allocate variables within code blocks. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2018-04-09 12:17 +0100
Re: Allocate variables within code blocks. "itsme.susila" <itsme.susila@gmx.com> - 2018-04-10 00:27 +0800
Re: Allocate variables within code blocks. Steven Petruzzellis <frelwizzen@gmail.com> - 2018-04-09 09:33 -0700
Re: Allocate variables within code blocks. Spiros Bousbouras <spibou@gmail.com> - 2018-04-09 16:52 +0000
Re: Allocate variables within code blocks. "itsme.susila" <itsme.susila@gmx.com> - 2018-04-10 01:17 +0800
Re: Allocate variables within code blocks. scott@slp53.sl.home (Scott Lurndal) - 2018-04-09 18:03 +0000
Re: Allocate variables within code blocks. supercat@casperkitty.com - 2018-04-09 13:39 -0700
Re: Allocate variables within code blocks. scott@slp53.sl.home (Scott Lurndal) - 2018-04-09 20:53 +0000
Re: Allocate variables within code blocks. bartc <bc@freeuk.com> - 2018-04-09 12:23 +0100
Re: Allocate variables within code blocks. "itsme.susila" <itsme.susila@gmx.com> - 2018-04-10 00:39 +0800
Re: Allocate variables within code blocks. Tim Rentsch <txr@alumni.caltech.edu> - 2018-04-09 08:09 -0700
Re: Allocate variables within code blocks. Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2018-04-09 17:07 -0600
Re: Allocate variables within code blocks. supercat@casperkitty.com - 2018-04-09 16:28 -0700
Re: Allocate variables within code blocks. Steven Petruzzellis <frelwizzen@gmail.com> - 2018-04-10 00:46 -0700
Re: Allocate variables within code blocks. Tim Rentsch <txr@alumni.caltech.edu> - 2018-04-11 07:10 -0700
csiph-web