468,468 Members | 2,694 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,468 developers. It's quick & easy.

Another stuct problme

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
2 1037
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
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.

Similar topics

5 posts views Thread by Daniel Tan | last post: by
3 posts views Thread by Kathy Burke | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.