Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Programming problem

 
Post new topic   Reply to topic Printable version
 View previous topic  message for Mr. Ekted. Post :: Post I wanted to get my crank on, but inste...  View next topic  
Author Message
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Wed Nov 10, 2004 12:45 pm   Post maybe stupid    Post subject: Programming problem Reply to topic Reply with quote

State 3 ways that the following code can ever exit. Crashing or terminating the process does not count. If this is too easy for you, don't give away the answers. Let others try.

Code: Show/Hide
a = 1;

while (a)
   b++;

// how do we get here?

_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Wed Nov 10, 2004 1:01 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

<comment>Nice post #666. icon_smile.gif</comment>
_________________
Performance is often the art of cheating carefully. - James Gosling
Back to top
View users profile Send private message Add User to Ignore List
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Wed Nov 10, 2004 5:31 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

(answers attached so as to not ruin problem)



answers

answers.txt - 0.47 KB
File downloaded or viewed 60 time(s)
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Wed Nov 10, 2004 11:21 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Good but there are more.
Back to top
View users profile Send private message Add User to Ignore List
tansey
Novice


Joined: Nov 03 2004
Posts: 53
Offline

PostPosted: Thu Nov 11, 2004 9:27 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

besides the 3 thrown up there, couldn't you also overload the class of a's '=' operator to set it to 0 if rvalue is 1?
Back to top
View users profile Send private message Add User to Ignore List
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Thu Nov 11, 2004 11:50 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

perhaps, but that would be operator overloading again. I wonder what function the while(a) would call... does it do a != 0 so operator!= or perhaps it does a cast to a bool... if so than what would it do in c... where there are no bool's (integer cast?). Ekted probably would know.

Similarly you could use #define in a few different ways to get the desired result.

A different solution would be to start a different thread that does

while (1)
a = 0;

forever and that should do it... assuming a is a global variable... unfortunately I can't seem to find a simple c++ example showing multithreading, so I don't know exactly what the syntax would be... I guess it's the idea that counts though.
Back to top
View users profile Send private message Add User to Ignore List AIM Address
50% Packetloss
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Sep 09 2003
Posts: 561
Location: Santa Clarita, California
Offline

PostPosted: Fri Nov 12, 2004 1:49 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

#define while(a) while(0)
#define b++ break

Good game sons!!

Edit: Damn, didnt read your post, guess you already found these answers
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Fri Nov 12, 2004 9:19 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

Clue:

volatile int a;
Back to top
View users profile Send private message Add User to Ignore List
SuSE
Me measures good


Joined: Dec 02 2002
Posts: 2307
Offline

PostPosted: Fri Nov 12, 2004 12:11 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

I know!
Code: Show/Hide
<html>
   <form>
      <input type crash>
   </form>
</html>
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website
50% Packetloss
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Sep 09 2003
Posts: 561
Location: Santa Clarita, California
Offline

PostPosted: Fri Nov 12, 2004 4:24 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

You could use __asm to have the program self-modify itself. Maybe even have another thread edit the value of a while the program is in the loop, I dont know enough about multi-threading though. I tried looking up the volatile stuff and its beyond me.
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Sun Nov 14, 2004 3:36 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

volatile looks like it prevents the comipler from optimizing certain values by having it always read them from memory, rather than store in registers. Using volatile values and multithreading it looks like we could change a in different thread

Code: Show/Hide
volatile int a;

ThreadFunc()
{
  while(1)
    a = 0;
}

int main()
{
  int b;
  startThread(&ThreadFunc);

  a = 1;

  while (a)
     b++;

  return 0;
}

again, the exact syntax is beyond me. use AfxBeginThread or something like that if you use MFC and #include <windows.h>.

The assembly self modifing solution is a funny one 50%.
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sun Nov 14, 2004 8:45 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Good work everyone. This concludes the exercise.
Back to top
View users profile Send private message Add User to Ignore List
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Sun Nov 14, 2004 10:49 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

couldn't you just step over it in a debugger?
_________________

Back to top
View users profile Send private message Add User to Ignore List Visit posters website
1stStrike
Cute like a kitty


Joined: Dec 28 2002
Posts: 427
Offline

PostPosted: Sun Nov 14, 2004 10:54 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

psh. programming! who needs programming anyway? software is for the weak! tongue.gif
Back to top
View users profile Send private message Add User to Ignore List
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sun Nov 14, 2004 11:04 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

D1s, I don't think you quite understand the debugger commands. You can't just skip a section of code, that would cause quite a few problems and wouldn't be too useful. The only call it skipping because it's going too fast to see. icon_razz.gif (My wacko explanation)
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
D1st0rt
Miss Directed Wannabe


Age:37
Gender:Gender:Male
Joined: Aug 31 2003
Posts: 2247
Location: Blacksburg, VA
Offline

PostPosted: Sun Nov 14, 2004 11:06 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

ok, I really have no knowledge of debuggers since nothing I've done has been complex enough to require serious use... I just saw the "step over" button in VS
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Mon Nov 15, 2004 3:12 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

Cyan~Fire wrote:
D1s, I don't think you quite understand the debugger commands. You can't just skip a section of code, that would cause quite a few problems and wouldn't be too useful. The only call it skipping because it's going too fast to see. icon_razz.gif (My wacko explanation)


Yuo can change the value of EIP any time you like, as long as you know what you are doing. This effectively performs a JMP.
Back to top
View users profile Send private message Add User to Ignore List
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Mon Nov 15, 2004 7:15 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

In assembly debuggers, you can change the PC register and that will skip commands. I'm not sure I've ever seen that functionality on a 8086 debugger, but it's probably there.

But you can do it on some embedded system debuggers, because they give you the ability to manually change all of the registers.
_________________
Hyperspace Owner

Smong> so long as 99% deaths feel lame it will always be hyperspace to me
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Mon Nov 15, 2004 9:52 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

EIP is the program counter for Intel. In VC you can edit registers simply by typing new values for them.
Back to top
View users profile Send private message Add User to Ignore List
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Mon Nov 15, 2004 10:12 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

Oh? Interesting. I've been working mostly with Motorola chips thus far.

Never really used Microsoft's debugger, either.
Back to top
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Purge
Episode I > Eposide III
Jar-Jar is kool


Age:35
Gender:Gender:Male
Joined: Sep 08 2004
Posts: 2019
Offline

PostPosted: Mon Nov 15, 2004 3:18 pm   Post maybe stupid    Post subject: Reply to topic Reply with quote

Damn smart people... icon_confused.gif
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Trash Talk All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 293 page(s) served in previous 5 minutes.

phpBB Created this page in 0.635461 seconds : 47 queries executed (78.8%): GZIP compression disabled