> I have to use C for this program. I am using "The Complete Reference"
> Osborne
Then you are in the wrong newsgroup. You want comp.lang.c
By the way, your thread title is incorrect. You are not passing the
pointer by reference (of any sort). C has no reference mechanism, you
have to use a pointer to pointer. C++ does, but you aren't using it.
Brian
OP deleted his post, and reposted in c.l.c.
This assigns buff to p, not to a. To have a pointer to a, you would
need getbuff(char** p) which works, but is a lot of trouble.
> return buff;
> }
Why don't you just try
char* getbuff(void);
int main()
{
char* b = getbuff();
}
Bo Persson
> On Jul 27, 12:41�pm, "Default User" <defaultuse...@yahoo.com> wrote:
> > squid wrote:
> > > I have to use C for this program. �I am using "The Complete
> > > Reference" Osborne
> >
> > Then you are in the wrong newsgroup. You want comp.lang.c
> >
> > By the way, your thread title is incorrect. You are not passing the
> > pointer by reference (of any sort). C has no reference mechanism,
> > you have to use a pointer to pointer. C++ does, but you aren't
> > using it.
> OP deleted his post, and reposted in c.l.c.
I saw the later post to clc. "Deleting" posts is something at best
works partially. Many servers ignore all cancel requests, so you tend
to end up with a situation where some people see it and some don't. Not
to mention that it doesn't matter once others have seen it and replied.
It's not like the OP can remove the thread.
In general, it's better to post a reply that indicates the shift to a
new group.
Brian
> I saw the later post to clc. "Deleting" posts is something at best
> works partially. Many servers ignore all cancel requests, so you tend
> to end up with a situation where some people see it and some don't. Not
> to mention that it doesn't matter once others have seen it and replied.
> It's not like the OP can remove the thread.
>
OP asked me to delete my post on the grounds that it had his private
(as opposed to public posting) email. Hence I removed mine as a
favor. Good luck with that, though, John.
> On Jul 27, 11:27�am, squid <jvstew...@gmail.com> wrote:
>
> Oh. My. Goodness. There is so much wrong here, I don't know where to
> start.
>
> I guess first, you should post in comp.lang.c, as you are coding in
> the strict C subset.
That's an extremely ignorant attitude to take, just plain wrong.
Where in the C standard is there any definition of what any code does
when compiled as C++? Even one example?
If the OP's program can be corrected to be proper C++, who are you to
take it upon yourself to redirect him to comp.lang.c?
> > I am trying to pass a pointer to a function and in the function
> > allocate some memory for it using malloc
>
> Do not use malloc in a C++ program. Use new.
>
> > and then using it in the
> > calling function. �If I return the pointer in the function return
> > value and assign it to a pointer variable when I call the function it
> > works.
> > �But when I try to use the pointer I sent as a parameter it
> > says the pointer variable is undefined and I am unable to access the
> > allocated memory.
>
> What book are you using that doesn't discuss the fact that C++ uses
> pass-by-value?
What sources are you using that don't mention the fact that C++
actually has true pass by reference, although C does not?
--
Jack Klein http://JK-Technology.Com
FAQs for
news:comp.lang.c http://c-faq.com/
news:comp.lang.c++ http://www.parashift.com/c++-faq-lite/
news:alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html