doesnt any1 knw about "far" pointers in C??

Status
Not open for further replies.

tweety_bird_bunny

Journeyman
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...?????
 

kikass

Broken In
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);
}
}
 

ahref

In the zone
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
 

kikass

Broken In
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..
 

JGuru

Wise Old Owl
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.
 

tuxfan

Technomancer
kikass said:
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 :D 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.
 

hafees

In the zone
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.
 

tuxfan

Technomancer
Ahh! :)) Thanks for confirming hafees! I feel little better ;) Yes I do remember Segment:Offset methods. :)
 

kikass

Broken In
@ 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! :)
 
Status
Not open for further replies.
Top Bottom