Mail Archives: djgpp/2000/02/14/18:39:31
Jörg Schumann a écrit dans le message <38A81EDA DOT B586F57A AT kt DOT cybersurf DOT de>...
>Hello,
>
>I have the following question:
>
>Is it possible to define far pointers in djgpp
>as I have done in the following example with MSVC++?
>And:
>If so, which command line parameters do I have to
>specify? (e.g.: gcc -v example.c -o example )
>Thank you in advance. JSchumann
>-----------------------------------------------------
>
>#include <dos.h>
>#include <malloc.h>
>#include <stdio.h>
>
>void main( void )
>{
> void far *p; /* define pointer */
> unsigned int seg_val;
> unsigned int off_val;
>
> p = _fmalloc( 100 ); /* example for initialisation of p:
>allocate memory */
>
> seg_val = _FP_SEG( p ); /* get segment- and offset-address */
> off_val = _FP_OFF( p );
>
> printf("Pointer: %Fp\n" ,p);
> printf("Segment: %.4X\n",seg_val);
> printf("Offset : %.4X\n",off_val);
>
> _ffree(p); /* free memory */
>}
>
DJGPP supports "flat" memory only (full 32-bit). That means that the 16-bit
near far and so nightmare is now finished, and that your are now allowed to
wrirte plain C code for a PC.
The (unportable and bad C) example by Microsoft I suppose (void main() is
typical), becomes simply:
#include <stdio.h>
#include <stlib.h>
int main( void )
{
void *p;
p =malloc( 100 ); /* example for initialisation of p: allocate
memory */
if (p)
{
printf("Pointer: %p\n" ,(void*)p);
free(p); /* free memory */
}
}
--
-hs-
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkum.com/htm_cl
"It's specified. But anyone who writes code like that should be
transmogrified into earthworms and fed to ducks." -- Chris Dollin CLC
- Raw text -