473,385 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why this program is crashing ???

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
8 2014

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

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
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
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

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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Daragoth | last post by:
Hi, I'm writing a program using Metrowerks CodeWarrior 4.0 that determines the best possible combination of a data set by checking every possible combination. I found there were about 250,000,000...
14
by: Java and Swing | last post by:
static PyObject *wrap_doStuff(PyObject *self, PyObject *args) { // this will store the result in a Python object PyObject *finalResult; // get arguments from Python char *result = 0; char *in=...
20
by: ghyott | last post by:
hello, In my opinion the following code should crash when run with *(argv+1)="1234567890" and *(argv+2)="1234567890" . int main(int argc,char **argv) { char buf1; char buf2; char buf3;...
5
by: Kuku | last post by:
My Program is crashing at strupr(e2.n); int main() { struct emp {
3
by: Shawn August | last post by:
Hello: I am converting a working VB6 program to C#. During testing of the C# version, I noticed the ReadFile API is crashing. The parameters going into the this function are identical to the...
17
by: UJ | last post by:
Is there any way for a windows service to start a windows program ? I have a service that will need to restart a windows app if it needs to. TIA - Jeff.
2
by: doug | last post by:
Hi all, Can anyone help me with the following dilema: I have been provided with a 3rd party threaded library (say libfoo.a) believed to be stable, it has been in use for a few years and noone...
41
by: z | last post by:
I use Visual C 2005 to develop my programs. One in particular is crashing in very specific and hard to replicate situations, made worse by the fact it only crashes when run -outside- the dev - as...
3
by: plbaldri | last post by:
I have written a very simple and basic program for an intro Comp Sci class and am having trouble with it crashing. The program needs to accept a filename on the command line at the prompt and has to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.