public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* C++: Is there a Value used to designate the end-of-an-array for non-char  arrays?
@ 2006-01-23  8:08 Robert Miesen
  2006-01-23 12:11 ` John Love-Jensen
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Robert Miesen @ 2006-01-23  8:08 UTC (permalink / raw)
  To: gcc-help

Hi.

I am curious if there is any sort of value used to designate the end of 
an array for arrays that are not of type char. I checked the book, "The 
C Programming Language", the book, "C++: The Complete Reference, 4th 
ed.", and briefly checked and found no information on the value used to 
designate the end of a non-character array.

Does such an end-of-array value exist for arrays that are not character 
arrays? Thank you for your responses in advance

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C++: Is there a Value used to designate the end-of-an-array  for non-char  arrays?
  2006-01-23  8:08 C++: Is there a Value used to designate the end-of-an-array for non-char arrays? Robert Miesen
@ 2006-01-23 12:11 ` John Love-Jensen
  2006-01-23 14:08 ` Perry Smith
  2006-02-07 20:40 ` dch
  2 siblings, 0 replies; 4+ messages in thread
From: John Love-Jensen @ 2006-01-23 12:11 UTC (permalink / raw)
  To: Robert Miesen, MSX to GCC

Hi Robert,

> I am curious if there is any sort of value used to designate the end of
> an array for arrays that are not of type char.

Nothing in particular is used by convention.

You can create your own convention, if you so choose and it works for the
numbers you are working with.  For example, if I had an array of floats that
were between -1.0f and +1.0f, I could choose some arbitrary number, say
2.0f, to represent end-of-array.

Alternatively, I could associate an array length size_t and not have an
explicit end-of-array value.

HTH,
--Eljay

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C++: Is there a Value used to designate the end-of-an-array for non-char  arrays?
  2006-01-23  8:08 C++: Is there a Value used to designate the end-of-an-array for non-char arrays? Robert Miesen
  2006-01-23 12:11 ` John Love-Jensen
@ 2006-01-23 14:08 ` Perry Smith
  2006-02-07 20:40 ` dch
  2 siblings, 0 replies; 4+ messages in thread
From: Perry Smith @ 2006-01-23 14:08 UTC (permalink / raw)
  To: Robert Miesen; +Cc: gcc-help

In general, no.

For some specific instances, there is a value but that value is put  
there by the C code (or C++ code) and not the "language" or the  
compiler.  For example, the main program is called as:  int main(int  
argc, char *argv[])  The argv array is an array of pointers to  
strings.  The last entry in the array is a null pointer.  But, as I  
said, that is set up by other code before main is called.

So, if you are writing just the receiving part of such an interface,  
check with the side that is creating the array to see if they are  
doing something similar.  Or if you are creating both sides of the  
interface, then you can design and implement whatever you desire.   
Often, with an array of structures, a particular field in the  
structure is given a special value that should never otherwise occur.

HTH,
Perry


On Jan 23, 2006, at 2:08 AM, Robert Miesen wrote:

> Hi.
>
> I am curious if there is any sort of value used to designate the  
> end of an array for arrays that are not of type char. I checked the  
> book, "The C Programming Language", the book, "C++: The Complete  
> Reference, 4th ed.", and briefly checked and found no information  
> on the value used to designate the end of a non-character array.
>
> Does such an end-of-array value exist for arrays that are not  
> character arrays? Thank you for your responses in advance
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C++: Is there a Value used to designate the end-of-an-array for  non-char  arrays?
  2006-01-23  8:08 C++: Is there a Value used to designate the end-of-an-array for non-char arrays? Robert Miesen
  2006-01-23 12:11 ` John Love-Jensen
  2006-01-23 14:08 ` Perry Smith
@ 2006-02-07 20:40 ` dch
  2 siblings, 0 replies; 4+ messages in thread
From: dch @ 2006-02-07 20:40 UTC (permalink / raw)
  To: Robert Miesen; +Cc: gcc-help

Hi Robert,

Unless you're dealing with legacy code, then with C++ std::vector or or 
std::list are the way to go.  These container classes come with end() 
methods which allow you to detect when you've reached the end of the 
container.  Even if you are dealing with legacy code, it is possible to 
pass vectors as arrays in most cases, althougth this would probably 
require more code changes than you want.

HTH,
David.

Robert Miesen wrote:

> Hi.
>
> I am curious if there is any sort of value used to designate the end 
> of an array for arrays that are not of type char. I checked the book, 
> "The C Programming Language", the book, "C++: The Complete Reference, 
> 4th ed.", and briefly checked and found no information on the value 
> used to designate the end of a non-character array.
>
> Does such an end-of-array value exist for arrays that are not 
> character arrays? Thank you for your responses in advance
>
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-02-07 20:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-01-23  8:08 C++: Is there a Value used to designate the end-of-an-array for non-char arrays? Robert Miesen
2006-01-23 12:11 ` John Love-Jensen
2006-01-23 14:08 ` Perry Smith
2006-02-07 20:40 ` dch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).