471,310 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Why doesn't "checked" work for sub calls?

Dear Members
Hi,
I have a question:
Why doesn't "checked" work for sub calls? For example consider the
following snippet of code:

checked
{
Overflower();
}

void Overflower()
{
int t=int.MaxValue;
t++;
}

Why Overflower doesn't throw overflow exception?
Sep 17 '08 #1
1 1059

"AliRezaGoogle" <as*******@yahoo.comwrote in message
news:0f**********************************@x35g2000 hsb.googlegroups.com...
Dear Members
Hi,
I have a question:
Why doesn't "checked" work for sub calls?
A fairly complex path could be created if allowed.

Imagine something like this:

public static void Main()
{
checked
{
RunProgram();
}
}

Can you imagine the overhead with this? Ouch!
For example consider the
following snippet of code:

checked
{
Overflower();
}

void Overflower()
{
int t=int.MaxValue;
t++;
}

Why Overflower doesn't throw overflow exception?
Because it is not checked.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

Subscribe to my blog
http://feeds.feedburner.com/GregoryBeamer#

or just read it:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think outside the box! |
********************************************

Sep 17 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

40 posts views Thread by Steve Juranich | last post: by
5 posts views Thread by VB Programmer | last post: by
22 posts views Thread by campbellbrian2001 | last post: by
7 posts views Thread by relient | last post: by
5 posts views Thread by Notgiven | last post: by
reply views Thread by rosydwin | last post: by

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.