![]() |
Typedef Struct as function input
Is there a way to have typedef struct's as input to a function? EG:
Code:
void Function(typedef struct data) |
Re: Typedef Struct as function input
Shouldn't a pointer work?
|
Re: Typedef Struct as function input
Look at this white paper it uses structs as inputs to functions quite a few times http://www.chiefdelphi.com/forums/pa...le&paperid=517
|
Re: Typedef Struct as function input
Quote:
The way I think it's supposed to work (but isn't) would be to have something like... Code:
void Function(*data); |
Re: Typedef Struct as function input
Quote:
|
Re: Typedef Struct as function input
Quote:
seems to me you want... typedef struct{ int blah; } typedef_example; void Function (typedef_example data) { printf("%s \n", data.blah); } void main () { typedef_example data; data.blah = 1; Function (data); } |
Re: Typedef Struct as function input
OK, so I've solved some problem and caused some more.
Right now my code is... Code:
void Func(struct typedef_example *variable);EDIT: The error is on Func(object_example); |
Re: Typedef Struct as function input
Quote:
Code:
void Func(struct typedef_example *variable);
That said, it is possible that C supports this odd annonymous struct typedefed thing, but the way I'd do it would be: Code:
void Func(struct typedef_example *variable); |
Re: Typedef Struct as function input
Quote:
|
Re: Typedef Struct as function input
Here's what I learned to do..
First, I define the the structure: Code:
typedef structFor example, Code:
void ShowStructData (pExampleType ExampleTypeAsPointer) // Since the function expects |
Re: Typedef Struct as function input
Quote:
|
Re: Typedef Struct as function input
Quote:
Code:
#include <stdio.h> |
Re: Typedef Struct as function input
Quote:
|
Re: Typedef Struct as function input
Quote:
One concept of "good programming technique" is to keep the variable's scope so that only functions that require access to it are able to. Structures are variables and this rule applies. In general you want to try to keep as few globals as possible. Instead, declare a variable static in a function; that will keep the value of the variable after it is removed from the stack (gone to a different function.) |
| All times are GMT -5. The time now is 04:35. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi