🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2316

Re: void* type

#2316
From: Kurt Watzka
Date: Sun, 17 Mar 1996 22:18
37 lines
1314 bytes
yang@math.umass.edu (Huayong Yang) writes:

>I know void* means an arbitrary pointer. In an interview, I was asked to
>write a routine that swaps two pointers.

>I tried with this

>void Swap(void** p1, void** p2)

This is a routine to swap two "void *". It is _not_ a general pointer-
swapping routine.

>{
>  void* p = *p1;
>  *p1 = *p2;
>  *p2 = *p;

If you swap two integers, you don't dereference your "swap" variable.
You should _not_ do so when dealing with pointers.

   *p2 = p;

would be good enough in a routine that swaps two void pointers.

>}

>but it is not correct, because void* is not allowed as operand.

It is not allowed to dereference a void *, not is it necessary in
this example.

Kurt
--
| Kurt Watzka                             Phone : +49-89-2180-6254
| watzka@stat.uni-muenchen.de
| ua302aa@sunmail.lrz-muenchen.de
Technical Details
Message-ID: <4ii34g$nlp@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4iepre$ag7@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: watzka@stat.uni-muenchen.de (Kurt Watzka)
Newsgroups: comp.lang.c.moderated
Subject: Re: void* type
Date: 17 Mar 1996 16:18:56 -0600
Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4ii34g$nlp@solutions.solon.com>
References: <4iepre$ag7@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com