my first real program!!

Started by
35 comments, last by bluefox25 16 years, 11 months ago
Quote:Original post by Spoonbender
Quote:Original post by Washu
Yes, pointing a pointer outside of the bounds defined (that is the start to one past the end) is undefined. No dereferencing required. Imagine a segmented system.

Just curious here, but what *would* happen in a segmented system?

Assuming you've used a segmented memory system before: Imagine what would happen when dealing with the difference between a long pointer and a short one. Think about the behavior of moving the pointer to before the block of memory it points to. Depending on pointer casts that may/may not be present, this could actually result in a[n] NOT being anywhere near your array. This is but one example. Other examples that come to mind: Some embedded systems actually have address registers that have some limited validation semantics associated with them. Specifically, certain blocks of addresses are reserved and cannot be pointed to. In those cases that subtraction trick can result in your pointer ending up in one of those regions, which would result in a hardware exception (that would have to be caught and handled by the RTOS).

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Advertisement
I can't help but feel a littlbe bit responsible for the healthy debate sparked by my newbie post :)
Gratz on your first program. Here's a suggestion: add the capability to have a variable number of tests, quizzes, etc. Extra credit if you can do it without needing limits on the numbers in your code (assuming they will be reasonable).

Also, rather than this:
    for ( i = 1; i < 4; ++i ) 
it would be more clear if you did this:
    for ( i = 1; i <= 3; ++i ) 

This form is a convention that C programmers have used for a long time:
    for ( i = 0; i < N; ++i ) 
It is interpreted as "for the first N elements". If you diverge from the convention slightly, it will confuse people who assume it is following the convention. So, it might be better to abandon the convention completely rather than slightly.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Wouldn't setting i = 1 be undefined as others have stated and debated? I like using i <= 3 because it would include up to 3 right?

BTW, how can I get a pic instead of the blue box? Maybe Ican find a pic of a lue fox!!
Quote:Original post by bluefox25
Wouldn't setting i = 1 be undefined as others have stated and debated? I like using i <= 3 because it would include up to 3 right?


"i <= 3" includes 3, which is what you want. "i = 1" does not give you undefined behavior. The undefined behavior happens when you go beyond the bounds of the array. That is what the "debate" was about.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
How can I draw soid lines on a console app?
I can do this ______ but how do I do a solid verticl line? I want to make a square,triangle,rectagle,etc

This topic is closed to new replies.

Advertisement