By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,127 Members | 1,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,127 IT Pros & Developers. It's quick & easy.

Another stuct problme

P: n/a
struct b{//elements};

struct b* funcfoo(){
struct b* p={0};
//do something with p
return p;
}
int main(){
struct b*p=//call funcfoo
printf(*%d%s*,p->inte,p->str);
return 0;
}

///////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
SSSSSSEEEEEGMENTATION FAULTTTTT
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////////////
I am sure you know why ? This is a reapeated error I wasn't able to
memorize. It's on others next to me not me anyway, hehe. Thanx

Jul 12 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Potatoman wrote:
struct b{//elements};

struct b* funcfoo(){
struct b* p={0};
//do something with p
return p;
}
int main(){
struct b*p=//call funcfoo
printf(*%d%s*,p->inte,p->str);
return 0;
}

///////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
SSSSSSEEEEEGMENTATION FAULTTTTT
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////////////
I am sure you know why ? This is a reapeated error I wasn't able to
memorize. It's on others next to me not me anyway, hehe. Thanx
What you've shown us is not compilable code, so it doesn't segfault.

Guessing wildly at a fix, I'd say that someone has tried to dereference
a null pointer. Bad dog. Null biscuit.

--
Chris "at least there are no crumbs" Dollin
"People are part of the design. It's dangerous to forget that." /Star Cops/

Jul 12 '06 #2

P: n/a
On 12 Jul 2006 00:42:51 -0700, "Potatoman" <gu*************@yahoo.com>
wrote:
>struct b{//elements};

struct b* funcfoo(){
struct b* p={0};
//do something with p
It depends on what you do with p. Unless you assign a different value
to p (such as by using malloc), the printf in main will always yield
undefined behavior. In this case, you are lucky that this particular
type of undefined behavior yields a segmentation fault.
return p;
}
int main(){
struct b*p=//call funcfoo
printf(*%d%s*,p->inte,p->str);
return 0;
}

///////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
SSSSSSEEEEEGMENTATION FAULTTTTT
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////////////
I am sure you know why ? This is a reapeated error I wasn't able to
memorize. It's on others next to me not me anyway, hehe. Thanx

Remove del for email
Jul 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.