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


Groups > comp.lang.c > #2677

Re: length of strings in a two dimensional array

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: length of strings in a two dimensional array
Date 2011-04-20 23:13 +1200
Message-ID <917tegFl0hU3@mid.individual.net> (permalink)
References <1f5669eb-6ab6-4dd7-a9e4-486134774dc0@r4g2000prm.googlegroups.com> <bmcsq69j3rrg74953159rbrglg7kif9iu6@4ax.com> <b5f8b3cf-0463-4770-85b6-91614d4037b3@cu4g2000vbb.googlegroups.com> <iomecv$8ot$1@dont-email.me>

Show all headers | View raw


On 04/20/11 11:00 PM, James Kuyper wrote:
> 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)

Did you intend to loose the trailing '\0'?

-- 
Ian Collins

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


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