473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

question about array bounds checking

I'm reading the O'Reilly's Progamming C# book and I have a question about
array bounds checking. On page 174, near the top, they show an example
where c# does indeed to array bounds checking cause the example shows a
System.IndexOutOfRangeException being thrown. However, in the very next
section (Jagged arrays) they have warning section that says "Java
programmers take note: While Java does bounds checking on array use, C# does
not." Huh? I hope you can see my confusion, in one case, it's clear C#
does cause it's throwing an exception, but yet at the bottom of the page it
says C# doesn't do it. Which is right?

Thanks.
Nov 16 '05 #1
6 3638
Flip,

I would think that the second section is incorrect. I don't have the
book, so I don't know exactly what it says, but .NET definitely does
checking on array bounds (however, it can be shut off, perhaps there is a
comment about that somewhere in the book).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Flip" <[remove]ph******@hotmail.com> wrote in message
news:Oj**************@TK2MSFTNGP10.phx.gbl...
I'm reading the O'Reilly's Progamming C# book and I have a question about
array bounds checking. On page 174, near the top, they show an example
where c# does indeed to array bounds checking cause the example shows a
System.IndexOutOfRangeException being thrown. However, in the very next
section (Jagged arrays) they have warning section that says "Java
programmers take note: While Java does bounds checking on array use, C#
does
not." Huh? I hope you can see my confusion, in one case, it's clear C#
does cause it's throwing an exception, but yet at the bottom of the page
it
says C# doesn't do it. Which is right?

Thanks.

Nov 16 '05 #2
Flip <[remove]ph******@hotmail.com> wrote:
I'm reading the O'Reilly's Progamming C# book and I have a question about
array bounds checking. On page 174, near the top, they show an example
where c# does indeed to array bounds checking cause the example shows a
System.IndexOutOfRangeException being thrown. However, in the very next
section (Jagged arrays) they have warning section that says "Java
programmers take note: While Java does bounds checking on array use, C# does
not." Huh? I hope you can see my confusion, in one case, it's clear C#
does cause it's throwing an exception, but yet at the bottom of the page it
says C# doesn't do it. Which is right?


That sounds very wrong. I don't have the book myself - could you post
the entire paragraph?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
I just got a reply back from the author and I was pointed to the errata
webpage where it says.

"Page 174 [2/16/04]
Note at bottom of page (Java Programmers take note...) Please remove this
note as it is incorrect; C# does provide bounds checking for arrays."

So C# does indeed to bounds checking on our behalf. :>
Nov 16 '05 #4
> That sounds very wrong. I don't have the book myself - could you post
the entire paragraph?

Thanks for the reply, however I don't believe that will be necessary (type
paragraph out I mean). I found out c# does indeed do bounds checking and it
was part of the errata section on the author's website.

Thanks again.
Nov 16 '05 #5
Flip,

It should be important to note that it is not C# that does this (it is
just a language) but rather, the .NET runtime that does this for you (the
bounds checking).

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Flip" <[remove]ph******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I just got a reply back from the author and I was pointed to the errata
webpage where it says.

"Page 174 [2/16/04]
Note at bottom of page (Java Programmers take note...) Please remove this
note as it is incorrect; C# does provide bounds checking for arrays."

So C# does indeed to bounds checking on our behalf. :>

Nov 16 '05 #6
> It should be important to note that it is not C# that does this (it is
just a language) but rather, the .NET runtime that does this for you (the
bounds checking).

True! I guess this is a bit of java-bias I still have to work out of my
system! :> In know, I know, in java, it's much the samething (java =
language) and it's the jvm that does this. But you can't run java without
the jvm, so easier to think of those two as one and the same. Not entirely
accurate, but helps a newbie learn things. :>

Thank again for your clarifications.
Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: agascoig | last post by:
I am just starting to learn Java J2RE 5.0. I coded the matrix library below and found that the array accessing is really slow since each access is checked: ...
26
by: Sterten | last post by:
when I define int R; and then later access it with x=R;C=7; .... but x happens to be <0 or >99 , then the program's behavious becomes unpredictable. Is there a way to prevent this ? Is...
31
by: RS | last post by:
Hi, Looking to see if the following construct is valid: typedef struct { int foo; char bar; } foobar; Basically, the idea is to have the structure above point to a message buffer that has...
22
by: Neo | last post by:
Hi Folks, #include<stdio.h> int main() { int (*p); int arr; int i;
8
by: ais523 | last post by:
I've checked the FAQ for this and couldn't find the answer. Is the following code snippet portable? int a; a=6; printf("%d\n",(*a)); This prints "6" on my compiler. I've been told it's...
26
by: Adam Warner | last post by:
Hi all, One cannot return a pointer to an array type in C because C has no first class array types. But one can return a pointer to a struct containing an incomplete array via the illegal but...
125
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this...
152
by: vippstar | last post by:
The subject might be misleading. Regardless, is this code valid: #include <stdio.h> void f(double *p, size_t size) { while(size--) printf("%f\n", *p++); } int main(void) { double array = { {...
8
by: Dan | last post by:
Hey hey, I'm trying to code a program for generating cyclic cellular automaton (http://en.wikipedia.org/wiki/Cyclic_cellular_automaton) and have gotten it working well enough to generate pretty...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.