•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,526 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,832 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1951 | Replies: 5
![]() |
•
•
Join Date: Oct 2004
Location: India
Posts: 47
Reputation:
Rep Power: 5
Solved Threads: 0
#include<iostream.h>
int main()
{
enum flag{ x=1,y=2,z=4,e=8};
flag f2=flag(99); // out of range
return 0;
}In this code the range of flag is 0:15 but it still compiles when 99 is entered which is out of range!!
Life is not a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming --WOW -- " What a ride!!! " -James Fineous McBride
•
•
Join Date: Oct 2004
Location: India
Posts: 47
Reputation:
Rep Power: 5
Solved Threads: 0
Well, I tried this because this was given as an example in Bjarne Stroustrup's book..but I couldn't get the result he specified!
Life is not a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming --WOW -- " What a ride!!! " -James Fineous McBride
>I tried this because this was given as an example in Bjarne Stroustrup's book
If you're citing a reference, give us sections and/or page numbers. Luckily, I both have that book and know what part of it you're talking about. It's page 77 in my most recent copy, section 4.8, Enumerations.
>but I couldn't get the result he specified!
You must have missed the comment:
Undefined means you can do it and the compiler probably won't even warn you, but it's not guaranteed to do anything expected, and there's nothing stopping undefined behavior from doing very real damage. I've heard stories of undefined behavior blowing out CRT monitors and wiping hard drives. Granted, that's an extreme, but the possibility should be more than enough to get you thinking.
If you're citing a reference, give us sections and/or page numbers. Luckily, I both have that book and know what part of it you're talking about. It's page 77 in my most recent copy, section 4.8, Enumerations.
>but I couldn't get the result he specified!
You must have missed the comment:
flag f4 = flag(99); // undefined: 99 is not within the range of flag
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,184
Reputation:
Rep Power: 38
Solved Threads: 930
c and c++ compilers do not do range checking on enumerations or pointers. It lets you hang yourself with a very very long rope if you want to. Its up to the programmer to validate data ranges and buffer sizes before using or doing something with them. Those are two very good reasons for c++ programs to use the STL classes.
•
•
Join Date: Oct 2004
Location: India
Posts: 47
Reputation:
Rep Power: 5
Solved Threads: 0
Yes, I meant that very topic from the book. Thanks for the replies!
Life is not a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming --WOW -- " What a ride!!! " -James Fineous McBride
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- input signal out of range? (Windows 9x / Me)
- C++ Data Types (C++)
- Computer Monitor is out of range (Windows 9x / Me)
- Input Signal Out of Range (Windows NT / 2000 / XP / 2003)
Other Threads in the C++ Forum
- Previous Thread: question on Stacks push,pop.
- Next Thread: Help!!!!!! General Protection Exception



Linear Mode