Forum     

Go Back   Digit Technology Discussion Forum > Portables, Peripherals and Electronics > QnA (read only)
Register FAQ Calendar Mark Forums Read

QnA (read only) Mods please help transfer the contents of this forum to proper sections. :)


 
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-08-2006, 12:09 AM   #1 (permalink)
In The Zone
 
tweety_bird_bunny's Avatar
 
Join Date: Oct 2003
Posts: 211
Default doesnt any1 knw about "far" pointers in C??


i referred to a c prgrm in yashwant kanetkar's buk "let us C" regarding dancing dolls program....

it uses far pointer in it.....

but the standard c compiler doesnt supprt it...
plz tel me if any1 knws how can i use far pointers in my program...

which compiler to use...?????
tweety_bird_bunny is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 10-08-2006, 08:33 AM   #2 (permalink)
Apprentice
 
Join Date: Jul 2004
Location: Pune
Posts: 70
Default Re: doesnt any1 knw about "far" pointers in C??

far pointers are used to manipulate/access memory outside of what has been allotted to TC (or any other compiler you are running). i dont remember what 'dancing dolls' program is ! but as i far as i can gather it is that case conversion thing and yes you do have to use a far pointer in it coz you are directly accessing and modifying the VDU memory (which obviously doesnt comes under your compiler's memory block).

here is the code.... i made this a long long time back... for a comp runnin win 98.. still it works though not for the entire screen coz the number of rows on the dos prompt has increased since then...


#include<stdio.h>
#include<conio.h>
#include<dos.h>


void main()
{

int i,flag=0;
char far *v=(char far *)0xB8000000;

while(!kbhit())
{
fflush(stdin);
for(i=0; i<4000; i=i+4)
{
if(*(v+i)>=65 && *(v+i)<=90)
*(v+i)=*(v+i)+32;
else
if(*(v+i)>=97 && *(v+i)<=122)
*(v+i)=*(v+i)-32;
flag=1;
}
if(flag==1)
{
for(i=2; i<4000; i=i+4)
{
if(*(v+i)>=65 && *(v+i)<=90)
*(v+i)=*(v+i)+32;
else
if(*(v+i)>=97 && *(v+i)<=122)
*(v+i)=*(v+i)-32;
}
}
delay(150);
}
}
kikass is offline  
Old 10-08-2006, 09:26 AM   #3 (permalink)
eWebGuru
 
ahref's Avatar
 
Join Date: Mar 2006
Location: Dehradun
Posts: 427
Default Re: doesnt any1 knw about "far" pointers in C??

To make dancing doll program in 'C' you have to use TSR (Termiate and stay resident). Logic is same as above, but above mentioned program will not stay in memory after termination. Turboc 3 supports far pointer, and you can make TSR program also with TC3
__________________
Windows and linux hosting at http://www.ewebguru.com
Get $50 per blog post PM me for details.
ahref is offline  
Old 10-08-2006, 10:38 AM   #4 (permalink)
Apprentice
 
Join Date: Jul 2004
Location: Pune
Posts: 70
Default Re: doesnt any1 knw about "far" pointers in C??

yeah....^^ahref is right.... i forgot to mention... this program when executed will run as long as you dont press a key.... (loop is while(!kbhit())
and from the ranges you can see that only the alphabets are affected..
kikass is offline  
Old 10-08-2006, 01:15 PM   #5 (permalink)
Wise Old Owl
 
JGuru's Avatar
 
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
Default Re: doesnt any1 knw about "far" pointers in C??

There are 'far', 'near', 'huge' pointers in C. I can't make you understand in couple of
sentences. You better read the book 'Understanding Pointers In C' by
Yashvant Kanetkar. It discusses them in detail. It's also a very good book for an in-depth
understanding of Pointers in C language.
JGuru is offline  
Old 10-08-2006, 05:47 PM   #6 (permalink)
Human Spambot
 
tuxfan's Avatar
 
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
Default Re: doesnt any1 knw about "far" pointers in C??

Quote:
Originally Posted by kikass
yeah....^^ahref is right.... i forgot to mention... this program when executed will run as long as you dont press a key.... (loop is while(!kbhit())
and from the ranges you can see that only the alphabets are affected..
There is a HUGH HUGH difference between a TSR and while(!kbhit())

TSR = Terminate and Stay Resident. Your application is not a TSR! As soon as a key is hit, it will come to and end! TSR are different. Search at Wikipedia for more.

Well, I have forgotten my C theory and completely lost touch but as far as I remember, far pointers are used because of following.

Pointers are 4 bytes - so max number of memory locations they can access is 65536 i.e. 64K. But memories are much larger. So memory is divided into segments of 64K each. Now when you need to access memory beyond a current block, you need to use a far pointer!

For example, when you declare a normal pointer, it may be within the current block where the application is working, so a normal pointer is alright. But if you need to access specific positions in memory like the starting point of video memory or status of caps/num/ins/scroll locks, then you need to use a far pointer because they are located beyond the current block of memory.

I may be technically wrong somewhere in this explanation

BTW, if you need to have some functions like savescreen(), restorescreen(), etc. in C, you can download them all or know more about them from here I had made some 50 general purpose functions that were damn useful to me and many others. But they are old and can be used only in C under DOS But at least they have some academic use.
tuxfan is offline  
Old 10-08-2006, 07:25 PM   #7 (permalink)
In The Zone
 
hafees's Avatar
 
Join Date: Feb 2004
Location: Kerala
Posts: 405
Default Re: doesnt any1 knw about "far" pointers in C??

you're right tuxfan.

Remember the Segment:Offset address methods? normal pointer can only refer offset locations i.e where the code block of the pgm.

For referring memory outside that segment we need a far or huge pointer.
__________________
Quitters Never Win & Winners Never Quit!
hafees is offline  
Old 11-08-2006, 10:35 AM   #8 (permalink)
Human Spambot
 
tuxfan's Avatar
 
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
Default Re: doesnt any1 knw about "far" pointers in C??

Ahh! Thanks for confirming hafees! I feel little better Yes I do remember Segment:Offset methods.
tuxfan is offline  
Old 11-08-2006, 10:30 PM   #9 (permalink)
Apprentice
 
Join Date: Jul 2004
Location: Pune
Posts: 70
Default Re: doesnt any1 knw about "far" pointers in C??

@ tuxfan
dude! i never claimed my code was for a TSR !!! it was just an example of using the far pointer to create the kind of effect the author wanted !!! anywayz chuck it!
kikass is offline  
Old 12-08-2006, 11:07 AM   #10 (permalink)
Human Spambot
 
tuxfan's Avatar
 
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
Default Re: doesnt any1 knw about "far" pointers in C??

Oh ok! I thought you have mixed up those too
tuxfan is offline  
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by clinton
- by Charan
- by icebags
- by ico
- by gohan89

Advertisement




All times are GMT +5.5. The time now is 11:15 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2