Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | James Kuyper <jameskuyper@verizon.net> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: length of strings in a two dimensional array |
| Date | 2011-04-20 07:00 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <iomecv$8ot$1@dont-email.me> (permalink) |
| References | <1f5669eb-6ab6-4dd7-a9e4-486134774dc0@r4g2000prm.googlegroups.com> <bmcsq69j3rrg74953159rbrglg7kif9iu6@4ax.com> <b5f8b3cf-0463-4770-85b6-91614d4037b3@cu4g2000vbb.googlegroups.com> |
On 04/20/2011 05:09 AM, dr.oktopus wrote:
>>
>>> const char messages[2][MESSAGE_LEN] = { &message_lo, &message_hi };
>>
>> Of course this is illegal since no part of messages contains any
>> address. �Did you perhaps mean to use #define instead of const char? �
Pay attention to the fact that this code is a constraint violation. It
doesn't matter what problems you might have with the alternative
approaches - this approach can not work, so you must choose one of the
alternatives.
> Using something like:
>
> #define message_lo "this is lowercase"
> #define message_hi "this is uppercase"
>
> prevents me to use the sizeof operator, so we return at the start
> point.
With the above #defines, nothing prevents you from using the expression
"sizeof message_lo"; the expression is an integer constant expression
which may be used for, among other things, the following uses:
#define MESSAGE_LEN (sizeof message_lo - 1)
const char messages[2][MESSAGE_LEN] =
{message_lo, message_high};
Note, among other things, the absense of the '&' operator from this
re-write.
--
James Kuyper
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
length of strings in a two dimensional array "dr.oktopus" <blindwilly@freeonline.zzn.com> - 2011-04-19 13:54 -0700
Re: length of strings in a two dimensional array "Morris Keesan" <mkeesan@post.harvard.edu> - 2011-04-19 17:07 -0400
Re: length of strings in a two dimensional array Barry Schwarz <schwarzb@dqel.com> - 2011-04-19 18:34 -0700
Re: length of strings in a two dimensional array "dr.oktopus" <blindwilly@freeonline.zzn.com> - 2011-04-20 02:09 -0700
Re: length of strings in a two dimensional array James Kuyper <jameskuyper@verizon.net> - 2011-04-20 07:00 -0400
Re: length of strings in a two dimensional array Ian Collins <ian-news@hotmail.com> - 2011-04-20 23:13 +1200
Re: length of strings in a two dimensional array James Kuyper <jameskuyper@verizon.net> - 2011-04-20 07:38 -0400
Re: length of strings in a two dimensional array "Mel Smith" <med_cutout_syntel@aol.com> - 2011-04-20 09:25 -0600
Re: length of strings in a two dimensional array "dr.oktopus" <blindwilly@freeonline.zzn.com> - 2011-04-20 09:51 -0700
Re: length of strings in a two dimensional array Ben Pfaff <blp@cs.stanford.edu> - 2011-04-20 10:07 -0700
Re: length of strings in a two dimensional array James Kuyper <jameskuyper@verizon.net> - 2011-04-20 19:57 -0400
Re: length of strings in a two dimensional array Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-04-20 08:12 -0400
Re: length of strings in a two dimensional array "dr.oktopus" <blindwilly@freeonline.zzn.com> - 2011-04-20 09:46 -0700
Re: length of strings in a two dimensional array Peter Nilsson <airia@acay.com.au> - 2011-04-20 15:11 -0700
Re: length of strings in a two dimensional array "dr.oktopus" <blindwilly@freeonline.zzn.com> - 2011-04-21 02:26 -0700
Re: length of strings in a two dimensional array Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-04-21 07:44 -0400
Re: length of strings in a two dimensional array Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-04-20 22:26 -0400
csiph-web