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

Why this program is crashing ???

P: n/a
Can Any one tell me why this program is crashing .

testFunc()
{
int a1[10], *ptr ;

f=&a1[0];
f=f+1;
return 0;
}

Mar 3 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a

code break wrote:
Can Any one tell me why this program is crashing .
NO. For why, see below.

testFunc()
int testFunc(void) /* much better style */
{
int a1[10], *ptr ;

f=&a1[0];
f=f+1;
return 0;
}


Because it's not a program? Show as a compilable minimum C program that
exhibits whatever problem you have. What you posted does not even
compile as a separate compilation unit to be later linked into a proper
program (e.g. you never define `f`).

Mar 3 '06 #2

P: n/a

code break wrote:
Can Any one tell me why this program is crashing .

testFunc()
{
int a1[10], *ptr ;

f=&a1[0];
f=f+1;
return 0;
}


A minimal program code please. What is f ?

Mar 3 '06 #3

P: n/a
This is not crashing its working absolutely fine.
Vladimir S. Oka wrote:
code break wrote:
Can Any one tell me why this program is crashing .


NO. For why, see below.

testFunc()


int testFunc(void) /* much better style */
{
int a1[10], *ptr ;

f=&a1[0];
f=f+1;
return 0;
}


Because it's not a program? Show as a compilable minimum C program that
exhibits whatever problem you have. What you posted does not even
compile as a separate compilation unit to be later linked into a proper
program (e.g. you never define `f`).


Mar 3 '06 #4

P: n/a
This is not crashing its working absolutely fine.
Vladimir S. Oka wrote:
code break wrote:
Can Any one tell me why this program is crashing .


NO. For why, see below.

testFunc()


int testFunc(void) /* much better style */
{
int a1[10], *ptr ;

f=&a1[0];
f=f+1;
return 0;
}


Because it's not a program? Show as a compilable minimum C program that
exhibits whatever problem you have. What you posted does not even
compile as a separate compilation unit to be later linked into a proper
program (e.g. you never define `f`).


Mar 3 '06 #5

P: n/a

Nikunj Shah wrote:
This is not crashing its working absolutely fine.
Please don't top post.

While you're at it, can you explain exactly how this works "absolutely
fine"?
Vladimir S. Oka wrote:
code break wrote:
Can Any one tell me why this program is crashing .


NO. For why, see below.

testFunc()


int testFunc(void) /* much better style */
{
int a1[10], *ptr ;

f=&a1[0];
f=f+1;
return 0;
}


Because it's not a program? Show as a compilable minimum C program that
exhibits whatever problem you have. What you posted does not even
compile as a separate compilation unit to be later linked into a proper
program (e.g. you never define `f`).


Mar 3 '06 #6

P: n/a
code break wrote:
Can Any one tell me why this program is crashing .
What program. I can't see a program in your post; all I see is a
function.
testFunc()
int testFunc(void)

or

int testFunc(...) /* this looks strange. I have to review variable
argument list material */
I prefer to specify return type and parameters explicitly rather than
relying on the defaults.
{
int a1[10], *ptr ;

f=&a1[0];
There's no scope for `f' at this point (unless it's a global variable).
Assuming it's been declared as int* or void*, I'd write that as

f = a1;

because the name of an array specifies the address of its first element,
and, for a simple assignment to a pointer the redundant "&" and "[0]"
actally make it less legible for me.
f=f+1;
return 0;
ptr has been declared but has never been used. Delete its declaration.
}

If you really have this function in some code of yours, as what it
really does is just return 0 to the caller, I think you could make your
program much simpler by removing the function and replacing it with a
constant zero instead;

Example (where foo has been defined as a int):
if (foo == testFunc()) { /* do something */ }
/* replace last line with */
if (foo == 0) { /* do something */ }

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Mar 3 '06 #7

P: n/a
code break wrote:
Can Any one tell me why this program is crashing .

testFunc()
{
int a1[10], *ptr ;

f=&a1[0];
f=f+1;
return 0;
}


What the f()***!

--
==============
*Not a pedant*
==============
Mar 3 '06 #8

P: n/a
Pedro Graca <he****@dodgeit.com> writes:
code break wrote:

[...]
testFunc()


int testFunc(void)

or

int testFunc(...) /* this looks strange. I have to review variable
argument list material */


A prototype with "..." requires at least one parameter before the "...".

Since testFunc doesn't use va_arg, there's no reason for it to have a
"..." in its prototype anyway.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 3 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.