www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/11/05/23:10:54

Message-ID: <3823A099.188880C8@lycosmail.com>
Date: Fri, 05 Nov 1999 22:29:30 -0500
From: Adam Schrotenboer <ajschrotenboer AT lycosmail DOT com>
X-Mailer: Mozilla 4.7 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: Pointers passed to functions
References: <4cGU3.2300$1J5 DOT 254437 AT typhoon DOT mbnet DOT mb DOT ca>
Reply-To: djgpp AT delorie DOT com

Are you trying to pass by vaslue, or by reference (passing the pointer?)

if you are trying to pass the pointer, then you have to modify your function
prototype something like this:

void draw_vimg(vimg &vectimg, int x, int y, int xscale, int yscale);

2nd, if you want to pass by value, why???? Perhaps I should also ask whether
that's really possible. The stack is only so large, and as a general rule, all
parameters are either passed on the stack, or pointers are passed on the stack.
Arrays are always passed as pointers. This may also apply to structs (can't
remember everything I've read) If you don't want to be able to modify the
contents, then try this:

void draw_vimg(const vimg vectimg, int x, int y, int xscale, int yscale);

Otherwise, you may have to make a copy of this object, which is what would be
done anyway if you want to pass by value.
The bad news is that you might not be able to say

newimage = oldimage; // Please, somebody out there with more experience, tell me
this can or cannot be done.

You might have to copy using memcpy, or similar. (Input from more experienced
programmers welcome. Eli?????)

Philip Bock wrote:

> I have a function whose definition looks like this: (vimg is a struct)
>
>     void draw_vimg(vimg vectimg, int x, int y, int xscale, int yscale);
>
> I want to pass it a vimg defined like so: (gen_vimg creates and sets initail
> values for the struct)
>
>     vimg *mygraphic;
>     mygraphic = gen_vimg();
>
> So I call draw_vimg like this:
>
>     draw_vimg(mygraphic, 200, 100, 1, 1);
>
> And I get errors like this:
>
>     vector.cpp: In function `int main()':
>     vector.cpp:45: conversion from `vimg *' to non-scalar type `vimg'
> requested
>
> So what can I do to send pointers to functions that call for variables, and
> not pointers too the variables?
>
> Thanks for your help. Philip.

- Raw text -


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