use of FAR pointers with gcc

T

tanuki

Hi guys,

sorry to ask this stupid question but how can i use far pointers in gcc ?

see, in tc i have something like :

int far *ptr= 0xb8000000;

gcc doesnt seem to have a far keyword


thanks
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi guys,

sorry to ask this stupid question but how can i use far pointers in gcc ?

see, in tc i have something like :

int far *ptr= 0xb8000000;

gcc doesnt seem to have a far keyword

'far' is not a C keyword

'far' is a keyword in /some/ extensions to C, and apparently not in gcc.

In other words, you can't use far pointers in gcc, and 'far' is not a part of
the C language.

- --
Lew Pitcher
IT Consultant, Enterprise Application Architecture,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFAuzu5agVFX4UWr64RAuitAKDGzTfMwwyn73PpfI74NHKu1wjJQQCfTuw3
fKlM7qaIkdAms2JfdbgkCKE=
=UDkq
-----END PGP SIGNATURE-----
 
S

Stephen L.

tanuki said:
Hi guys,

sorry to ask this stupid question but how can i use far pointers in gcc ?

see, in tc i have something like :

int far *ptr= 0xb8000000;

gcc doesnt seem to have a far keyword

thanks

No, gcc doesn't have a "far" keyword, as _far_ as I know... :)

What code from what architecture are you porting,
and to what architecture (I'm guessing Intel -> ??)?

You example looks `hardware'ish and may have
no meaning in the new architecture/OS.


Stephen
 
T

tanuki

well, i'm using gcc under windows on ia32 to point to video memory so that
i can write some stuff to that

i suppose that this would work under linux too if the program was executed
as root

if i just try something like long *ptr 0xb8000000
and write to it linux gives me a segfault and windows gives me a
"read/write" error

sorry about all this, i'm just really starting to learn the language
 
R

Richard Tobin

tanuki said:
if i just try something like long *ptr 0xb8000000
and write to it linux gives me a segfault and windows gives me a
"read/write" error

You seem to be expecting the video memory to exist at a specific place
in your program's memory. I don't know about Windows, but normal
operating systems like Linux provide virtual memory, and will not map
memory corresponding to devices into your address space unless you
specifically request it.

So your problem is how to map the video memory into your process, and
that will be done by some library function, most likely in conjunction
with opening some device. It's not a problem with your C pointers as
such.

-- Richard
 
E

Emmanuel Delahaye

tanuki said:
well, i'm using gcc under windows on ia32 to point to video memory so that
i can write some stuff to that

i suppose that this would work under linux too if the program was executed
as root

if i just try something like long *ptr 0xb8000000
and write to it linux gives me a segfault and windows gives me a
"read/write" error

sorry about all this, i'm just really starting to learn the language

This has nothing to do with the C language. It's a matter of system. Some
are unsafe and let you play with the hardware, others try to be safe and they
don't.

If you want to access the hardware from an application, you must use the
services provided by the system (Windows: DirectX or the like).

If you are writing a driver, well, you certainly are not a newbie in C...
 
?

=?iso-8859-1?q?Nils_O=2E_Sel=E5sdal?=

well, i'm using gcc under windows on ia32 to point to video memory so that
i can write some stuff to that

i suppose that this would work under linux too if the program was executed
as root

if i just try something like long *ptr 0xb8000000
and write to it linux gives me a segfault and windows gives me a
"read/write" error
Newer windows version, as well as linux uses virtual memory.
the 0xb8000000 address your process sees, is probably not the
physical adderess 0xb8000000 . You have to use some sort of API
these days to write to the screen, such as DirectX or OpenGL.
Or even the win32/mfc api on windows or X/any gui toolkit on linux.
 
L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Newer windows version, as well as linux uses virtual memory.
the 0xb8000000 address your process sees, is probably not the
physical adderess 0xb8000000 .

For that matter
a) that particular address is not guaranteed to be part of the program's memory
map, and 'direct' access to it can cause 'undefined' behaviour (SIGSEGV, memory
corruption, whatever the system deams appropriate).
b) even if the program has access to that address as part of it's memory map,
with virtual memory, that address probably doesn't belong to the same 'real
memory' location as the video memory.

You have to use some sort of API
these days to write to the screen, such as DirectX or OpenGL.
Or even the win32/mfc api on windows or X/any gui toolkit on linux.

On newer versions of MSWindows (WinNT/2K/XP), application programs need special
permissions to access hardware services like video memory. In Linux,
restrictions are even more severe; you need root access /and/ a special API to
get at video memory.


- --
Lew Pitcher
IT Consultant, Enterprise Application Architecture,
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed are my own, not my employers')
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFAu3A+agVFX4UWr64RApJTAJ4o0DV6AzQsnHCLO+HqDSujL3mfpwCeNxk2
sH44FBHmNDOWWx/ZmxFQcPw=
=ytug
-----END PGP SIGNATURE-----
 
T

tanuki

Thanks for your comments everyone..

I understand now why you would be able to access certain addresspaces
directly.
stupid old DOS programming examples had me somewhat confuzzled...

i was just playing arround with c and thought it might be a good idea to try
and
write directly to video memory :)
 
C

cody

if i just try something like long *ptr 0xb8000000
and write to it linux gives me a segfault and windows gives me a
"read/write" error

You cannot do this, neither under windows nor under *n*x, since every modern
OS's use virtual memory,
so you cannot rely on a specific address. Besides, a usermode app cannot
access video-memory directly.
If you want to do graphics programming use OpenGL or DirectX, or for simple
things where speed is not important use the GDI API from Windows.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top