Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ike Naar <ike@iceland.freeshell.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: passing a pointer to initialized structrue in a function |
| Date | 2012-03-02 17:25 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrn3vfsjl20jd.dls.ike@iceland.freeshell.org> (permalink) |
| References | <30546693.434.1330702765903.JavaMail.geo-discussion-forums@pbfa4> |
On 2012-03-02, ArifulHossain tuhin <etothepowerpi@gmail.com> wrote:
> I have this structure like following :
>
> typedef struct{
> char static_data[10];
> int a;
> int b;
> } my_ds;
>
> i have initialized it like following:
>
> my_ds * ds = (my_ds *)malloc(sizeof(my_ds));
> memmove(my_ds->static_data, buf, len);
Did you mean
memmove(ds->static_data, buf, len);
here ?
> ds->a = c;
> ds->b = d;
>
> and passed it in a function:
>
> int my_fun(void ** data);
> my_fun((void *)&ds);
>
> what happens inside my_fun, the first field, static[10] is initialized
> correctly but other two values are zero. What am i missing here?
Apart from a few stylistic things, I don't see problems in the code that
could explain the behaviour (assuming c and d were nonzero, and that
len <= 10).
Can you show a *complete* small program (one that we can compile and run
without having to guess about the missing parts) that exhibits the faulty
behaviour?
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
passing a pointer to initialized structrue in a function ArifulHossain tuhin <etothepowerpi@gmail.com> - 2012-03-02 07:39 -0800
Re: passing a pointer to initialized structrue in a function ArifulHossain tuhin <etothepowerpi@gmail.com> - 2012-03-02 07:44 -0800
Re: passing a pointer to initialized structrue in a function James Kuyper <jameskuyper@verizon.net> - 2012-03-02 11:26 -0500
Re: passing a pointer to initialized structrue in a function James Kuyper <jameskuyper@verizon.net> - 2012-03-02 11:45 -0500
Re: passing a pointer to initialized structrue in a function James Kuyper <jameskuyper@verizon.net> - 2012-03-02 11:47 -0500
Re: passing a pointer to initialized structrue in a function Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-03-02 17:02 +0000
Re: passing a pointer to initialized structrue in a function James Kuyper <jameskuyper@verizon.net> - 2012-03-02 13:53 -0500
Re: passing a pointer to initialized structrue in a function Ike Naar <ike@iceland.freeshell.org> - 2012-03-02 17:25 +0000
Re: passing a pointer to initialized structrue in a function cri@tiac.net (Richard Harter) - 2012-03-02 19:40 +0000
csiph-web