Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Dr Nick <3-nospam@temporary-address.org.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: flowto (Just for fun) |
| Date | 2011-07-11 20:11 +0100 |
| Message-ID | <87tyas1vk6.fsf@temporary-address.org.uk> (permalink) |
| References | (5 earlier) <slrn3vfsj1iq03.5fi.ike@sverige.freeshell.org> <87wrfqzcm3.fsf@temporary-address.org.uk> <slrn3vfsj1j29b.7t3.ike@sverige.freeshell.org> <87oc12z8rg.fsf@temporary-address.org.uk> <560904cf-67b6-4faf-ab24-f3a3c1b379bc@u26g2000vby.googlegroups.com> |
Nick Keighley <nick_keighley_nospam@hotmail.com> writes:
> On Jul 10, 12:15 pm, Dr Nick <3-nos...@temporary-address.org.uk>
> wrote:
>> If it's small and local and never used anywhere else then you might as
>> well just have it as an explicit naked value (with an explanatory
>> comment) rather than carefully creating an enum just to give it a name
>> for a one-off use right next to where it's defined.
>
> I think that's a mistake. If you're going to create a symbolic
> constant if you use it twice why not do it when you use it once. The
> same arguemtn applies to functions. Soem people use the rule "only
> create a function if it used more that once" and then up with monsters
>
> The same number can have many meanings in the same program
>
> base_station[9].port[9] = 9; /* write a tab to the control port
> of the last basestation */
I'm not entirely convinced that
enum {last_basestation=9};
enum (control_port=9};
enum {tab=9};
base_station[last_basestation].port[control_port] = tab;
is a lot clearer!
I think this is a different argument to avoiding putting a tidy piece of
code into a function.
I don't like the enum hack. If you also don't want to deal with the
scope issues of #defines you don't have much choice.
But it's not clear-cut. There's almost certainly a time and place for
all of them.
I'd be a lot more sympathetic to:
enum {main_basestation=9,sub_basestation=10};
enum (control_port=9,display_port=17};
enum {backspace=8,tab=9};
base_station[main_basestation].port[control_port] = tab;
base_station[sub_basestation].port[display_port] = backspace;
although I'd probably rewrite the enum names to put the common part
first (given that enums don't have a very good namespace).
--
Online waterways route planner | http://canalplan.eu
Plan trips, see photos, check facilities | http://canalplan.org.uk
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
Re: flowto (Just for fun) luser- -droog <mijoryx@yahoo.com> - 2011-07-07 00:03 -0700
Re: flowto (Just for fun) Dr Nick <3-nospam@temporary-address.org.uk> - 2011-07-07 08:06 +0100
Re: flowto (Just for fun) Shao Miller <sha0.miller@gmail.com> - 2011-07-07 19:34 -0400
Re: flowto (Just for fun) Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-07-08 02:39 +0300
Re: flowto (Just for fun) Keith Thompson <kst-u@mib.org> - 2011-07-07 17:09 -0700
Re: flowto (Just for fun) gwowen <gwowen@gmail.com> - 2011-07-08 03:10 -0700
Re: flowto (Just for fun) Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-07-10 04:44 +0300
Re: flowto (Just for fun) Ike Naar <ike@sverige.freeshell.org> - 2011-07-10 08:51 +0000
Re: flowto (Just for fun) Dr Nick <3-nospam@temporary-address.org.uk> - 2011-07-10 10:52 +0100
Re: flowto (Just for fun) Ike Naar <ike@sverige.freeshell.org> - 2011-07-10 11:12 +0000
Re: flowto (Just for fun) Dr Nick <3-nospam@temporary-address.org.uk> - 2011-07-10 12:15 +0100
Re: flowto (Just for fun) Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-07-11 03:32 -0700
Re: flowto (Just for fun) Dr Nick <3-nospam@temporary-address.org.uk> - 2011-07-11 20:11 +0100
Re: flowto (Just for fun) Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-07-10 20:42 +0300
Re: flowto (Just for fun) "io_x" <a@b.c.invalid> - 2011-07-11 08:08 +0200
Re: flowto (Just for fun) luser- -droog <mijoryx@yahoo.com> - 2011-07-10 23:51 -0700
Re: flowto (Just for fun) "io_x" <a@b.c.invalid> - 2011-07-11 09:15 +0200
Re: flowto (Just for fun) "io_x" <a@b.c.invalid> - 2011-07-08 20:06 +0200
csiph-web