hello all,
well I am getting really frustrated with something. I read on a post here that passing by value is supported in C, and that bassing by referance is only supported by C++. I am programming an program with a .CPP extension, but my application is using the C standard library and what I would consider at least 95% of C style code (I've yet to learn alot of C++).
anyways I also read here that passing structures by value can be beneficial over passing by reference with larger structures. I am just wondering how I can get the contents of the structure in my function. I keep trying different ways, and I keep getting errors. anyways here is what my code looks like:
my structure is larger than that, that is just an example (if it was that small, I wouldn't bother passing by pointer). as you can see I am totally unsure of things locally in somefunc(), and like I said I have tried just about every possible way I can think of and keep getting errors. if someone could please show me how things should look in somefunc(), it would be GREATLY appreciated.Code:typedef struct s { int i; char a; } S, *PS; void somefunc(PS); int main(void) { S var; PS pvar = &var; pvar->i = 10; pvar->a = 'b'; somefunc(pvar); return 0; } void somefunc(PS ps) { /* now, I would like to declare a local variable of s, but I don't know if I should use the S or PS type. I am assuming I should use a referance to assign the local variable the contents of ps, but I am also having problems with this. */ }
thank you very much in advance!