comp.lang.c
[Top] [All Lists]

Re: Doubts about pointers

Subject: Re: Doubts about pointers
From: jacob navia
Date: Wed, 26 Mar 2008 21:32:07 +0100
Newsgroups: comp.lang.c


Simon wrote:
Hello friends,

I have a couple of doubts about pointers in C.


1) I have a function with prototype is :

 my_funtion(char far * char);

I need to pass it an array of char which I have defined as follows:

 char my_array[10]

The question is: is it allright to typecast to a far pointer? e.g.
int i=my_function( (char far *) ( (char *) my_array );

I think I am still only passing a near pointer, so how do I force
the segment to be passed also?

If I remember correctly, the segment will be added when
you cast a near pointer to a far one, i.e. the current data
segment will be passed. You should look at the assembly
generated to be sure.


2) As expected, (char far *) NULL is NULL, but if I set
char near *x = NULL, then (char far *)x is non-NULL (the segment is non-zero)!

Probably because the data segment is added to the NULL pointer
see above...


This seems crazy, it means that if you have a prototyped function
with a far pointer argument (maybe NULL) and you have some
near-mode address from somewhere else (maybe NULL),
you have to handle the NULL case specially. What's going on?


I am using Borland Turbo-C 2.01 if it's relevant.


Forget that stuff. You are programming for a system that is
around 20 years old. All this stuff is obsolete.

P.S. There was in this group someone that loved TURBOC. I am
surprised he doesn't answer your question.

--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy