delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/02/14/18:39:31

From: "-hs-" <email DOT invalid AT server DOT invalid>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: void far *pointer
Date: Mon, 14 Feb 2000 23:56:56 +0100
Lines: 69
Message-ID: <88a17p$25gh$1@news5.isdnet.net>
References: <38A81EDA DOT B586F57A AT kt DOT cybersurf DOT de>
NNTP-Posting-Host: d164.paris-161.cybercable.fr
Mime-Version: 1.0
X-Trace: news5.isdnet.net 950569017 71185 212.198.161.164 (14 Feb 2000 22:56:57 GMT)
X-Complaints-To: abuse AT isdnet DOT net
NNTP-Posting-Date: 14 Feb 2000 22:56:57 GMT
X-Newsreader: Microsoft Outlook Express 4.72.3110.5
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019