Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Doubts about pointers

Reply
Thread Tools

Doubts about pointers

 
 
amit khan
Guest
Posts: n/a
 
      05-21-2010
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?

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)!

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.
 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      05-21-2010
amit khan <(E-Mail Removed)> writes:

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


It's about 21 years old. Have you considered using a more modern
C implementation?
--
Ben Pfaff
http://benpfaff.org
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      05-21-2010
On 05/22/10 09:21 AM, amit khan 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?


C (as in standard C) doesn't have near and far pointers. You should
find your answers in your compiler docs, or a group dedicated to its use.

--
Ian Collins
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      05-21-2010
On 2010-05-21, amit khan <(E-Mail Removed)> wrote:
> Hello friends,
>
> I have a couple of doubts about pointers in C.


No, you have a couple of doubts about pointers in your implementation.

> 1) I have a function with prototype is :
>
> my_funtion(char far * char);


You need a DOS or Windows newsgroup.

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


It is. Your question is unique to a non-standard feature of some DOS
and Windows implementations which had different kinds of pointers.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      05-22-2010
In article <(E-Mail Removed)>,
Ben Pfaff <(E-Mail Removed)> wrote:
>amit khan <(E-Mail Removed)> writes:
>
>> I am using Borland Turbo-C 2.01 if it's relevant.

>
>It's about 21 years old. Have you considered using a more modern
>C implementation?


Is there anything per se wrong with using something that is old?

Obviously, these people have good solid reasons for using TurboC.

--
> No, I haven't, that's why I'm asking questions. If you won't help me,
> why don't you just go find your lost manhood elsewhere.


CLC in a nutshell.

 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      05-22-2010
On 21 May, 22:30, Seebs <(E-Mail Removed)> wrote:
> On 2010-05-21, amit khan <(E-Mail Removed)> wrote:


> > I have a couple of doubts about pointers in C.

>
> No, you have a couple of doubts about pointers in your implementation.
>
> > 1) I have a function with prototype is :

>
> > *my_funtion(char far * char);

>
> You need a DOS or Windows newsgroup.
>
> > I am using Borland Turbo-C 2.01 if it's relevant.

>
> It is. *Your question is unique to a non-standard feature of some DOS
> and Windows implementations which had different kinds of pointers.


even windows doesn't use far pointers (did it ever?)

 
Reply With Quote
 
Tom St Denis
Guest
Posts: n/a
 
      05-22-2010
On May 22, 7:44*am, (E-Mail Removed) (Kenny McCormack)
wrote:
> In article <(E-Mail Removed)>,
> Ben Pfaff *<(E-Mail Removed)> wrote:
>
> >amit khan <(E-Mail Removed)> writes:

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

>
> >It's about 21 years old. *Have you considered using a more modern
> >C implementation?

>
> Is there anything per se wrong with using something that is old?


Well for one, there is no official support for it. So if you plan on
doing anything professionally [including education] with it you're at
a loss.

Also, DJGPP is freely available for DOS platforms. It also uses GCC
and is modern, supported, and a hell of a better compiler.

> Obviously, these people have good solid reasons for using TurboC.


I seriously 100% doubt that.

Tom
 
Reply With Quote
 
BGB / cr88192
Guest
Posts: n/a
 
      05-22-2010

"Nick Keighley" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On 21 May, 22:30, Seebs <(E-Mail Removed)> wrote:
> On 2010-05-21, amit khan <(E-Mail Removed)> wrote:


> > I have a couple of doubts about pointers in C.

>
> No, you have a couple of doubts about pointers in your implementation.
>
> > 1) I have a function with prototype is :

>
> > my_funtion(char far * char);

>
> You need a DOS or Windows newsgroup.
>
> > I am using Borland Turbo-C 2.01 if it's relevant.

>
> It is. Your question is unique to a non-standard feature of some DOS
> and Windows implementations which had different kinds of pointers.


<--
even windows doesn't use far pointers (did it ever?)
-->

Win 3.x and earlier...


16-bit apps in Win95-WinXP (NT-XP via NTVDM), but XP64, Vista, and Win7
dropped support for them...

Win32s (Win 3.x) and Win95 native and newer apps generally used 32-bit
memory, and so didn't make use of far pointers...

far pointers have some (limited) use WRT 32-bit code (on x86, and x86-64),
but this is mostly limited to OS kernel code and occassional edge cases
(mostly accessing thread-local-storage and similar), and hence most 32/64
bit compilers don't bother supporting them AFAIK (usually it is confined to
the occasional piece of ASM or inline ASM or similar).


on x86-64, segments are mostly broken, and left mostly as a vestigial
feature (although FS/GS remain as a special-case hack mostly to help
facilitate TLS/etc...).



 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      05-22-2010
In article <(E-Mail Removed)>,
Nick Keighley <(E-Mail Removed)> wrote:
....
>> It is. *Your question is unique to a non-standard feature of some DOS
>> and Windows implementations which had different kinds of pointers.

>
>even windows doesn't use far pointers (did it ever?)


Well, that is certainly a question of semantics (what this newsgroup
excels at). Certainly in Win16 days, it did. In Win32, it could be
said that all pointers are "far" - in that they are 32 bits, which in
the terminology of DOS/Windows is "far".

If you spend some time looking through the include files of a Windows C
installation, you will see that "far" is still a concept employed
therein. As far as I can tell (although I certainly didn't look in
great depth), in the current incarnation of things, "far" (and "FAR")
are #define'd to empty, so that the concept essentially drops out at
compile time. But it is still the case that "far" (or "FAR") is part of
the definition of WINAPI (and some other things).

P.S. In a way, your question would have been more poignant if you had
asked if they used "near" pointers. That question could, possibly, be
answered in the negative.

--
(This discussion group is about C, ...)

Wrong. It is only OCCASIONALLY a discussion group
about C; mostly, like most "discussion" groups, it is
off-topic Rorsharch [sic] revelations of the childhood
traumas of the participants...

 
Reply With Quote
 
Stargazer
Guest
Posts: n/a
 
      05-24-2010
> > >> I am using Borland Turbo-C 2.01 if it's relevant.
>
> > >It's about 21 years old. *Have you considered using a more modern
> > >C implementation?

>
> > Is there anything per se wrong with using something that is old?

>
> Well for one, there is no official support for it. *So if you plan on
> doing anything professionally [including education] with it you're at
> a loss.


For two, Turbo-C 2.01 was released even before ANSI C89 Standard.

> Also, DJGPP is freely available for DOS platforms. *It also uses GCC
> and is modern, supported, and a hell of a better compiler.


Unfortunately, it's not the same thing. DJGPP works only in 32-bit
flat mode and it requires a DOS extender. DOS extender is included in
the distro, but it won't work on pure real-mode DOS and won't work at
all on anything before 386.

Daniel
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pointers, pointers, pointers... cerr C Programming 12 04-07-2011 11:17 PM
Doubts about pointers Simon C Programming 71 03-31-2008 02:43 AM
c++: pointers to pointers A C++ 3 10-29-2003 01:15 PM
pointers to pointers // exception handling error muser C++ 3 09-18-2003 06:19 PM
Template specialization of pointers with function pointers Phil C++ 1 09-16-2003 02:17 AM



Advertisments