Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 11th, 2005, 6:27 AM   #1
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Post Linux - ASCII Code 27

I wrote this little program to show what I'm talking about:
[php]#include <iostream>

int main(int argc, char** argv)
{
std::cout<<char(27)<<std::endl;
return 0;
}[/php]

I'm using g++ to compile this, and when run it removes the first character of the next line in the terminal.

Example:
Quote:
Originally Posted by terminal
jack@slackbox:~/files/cpp$ g++ del.cpp -o del
jack@slackbox:~/files/cpp$ ./del

ack@slackbox:~/files/cpp$
Notice the missing "j" on the last line.

I was just wondering why it removed this character when printing the ASCII code for the escape key.

Can anyone enlighten me?


EDIT:
On further inspection, i found that if i remove the endl from the statement, the first character of the next line is not removed. This makes em even more confused as to why this is happening.
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Dec 11th, 2005, 6:34 AM   #2
metsfan
Programmer
 
Join Date: Dec 2005
Posts: 57
Rep Power: 0 metsfan is an unknown quantity at this point
this is a very interesting problem

i ran your code on my machine and it works just fine.

aeskreis@unix40 ~ $g++ del.cpp -o del
aeskreis@unix40 ~ $ ./del

aeskreis@unix40 ~ $

very strange indeed...it doestn seem to have any effect on the actual running or compiling of the program though
metsfan is offline   Reply With Quote
Old Dec 11th, 2005, 6:38 AM   #3
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Well heres some more details:

I'm running g++ version 3.3.6, and i'm using the 2.4 kernel (smite me).

Can you check your g++ and kernel versions.
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Dec 11th, 2005, 6:46 AM   #4
metsfan
Programmer
 
Join Date: Dec 2005
Posts: 57
Rep Power: 0 metsfan is an unknown quantity at this point
im running it from my school's computer so i have no clue what the kernel version is. the most info i could gather is that they are maybe running gnu v. 3.2, but this is carnegie mellon, so im going to assume they have hte most up-to-date versions of everything
metsfan is offline   Reply With Quote
Old Dec 11th, 2005, 6:49 AM   #5
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
run this:
cat /proc/version && g++ --version

You can copy and paste the output, if your not sure which part to look at.

EDIT:
I noticed that the box your on is called unix40. Are you sure its Linux? If so which distro?
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Dec 11th, 2005, 6:52 AM   #6
metsfan
Programmer
 
Join Date: Dec 2005
Posts: 57
Rep Power: 0 metsfan is an unknown quantity at this point
Linux version 2.4.30 (cg2v@manticore.andrew.cmu.edu) (gcc version 3.2.1) #3-i686+-UP (034) Wed May 11 16:33:00 EDT 2005
g++ (GCC) 3.2.1
metsfan is offline   Reply With Quote
Old Dec 11th, 2005, 7:00 AM   #7
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Interesting, your using the 2.4 kernel and using g++ 3.2.1.

My exact details are:
2.4.31 kernel
g++ 3.3.6

So it would appear that my box is more updated than your schools one. This is weird.
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Dec 11th, 2005, 7:06 AM   #8
metsfan
Programmer
 
Join Date: Dec 2005
Posts: 57
Rep Power: 0 metsfan is an unknown quantity at this point
Quote:
Originally Posted by coldDeath
Interesting, your using the 2.4 kernel and using g++ 3.2.1.

My exact details are:
2.4.31 kernel
g++ 3.3.6

So it would appear that my box is more updated than your schools one. This is weird.
yea apparently my school sucks, but being as they make CS majors write concurrent programs to do sorting algorithms and wythoff arrays in less than a week and making them due on sunday forcing us to pop adderal and pull all nighters, i kinda knew that already

yea, anyway asside from my rant on how CMU sucks, try running it on gnu 3.2 and see if it makes a difference, maybe its a bug in the newer version, or soemthing
metsfan is offline   Reply With Quote
Old Dec 11th, 2005, 7:46 AM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Systems can be set up so that various screen functions are performed in response to various escape sequences. If your system is set up for that, then transmitting an escape followed by various other values will Do Thangs (x-y positioning, clearing, etc.).
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Dec 11th, 2005, 5:02 PM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
ASCII 27 is equivalent to the escape key. This just happens to be what your terminal does when it encounters it.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:35 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC