473,372 Members | 846 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,372 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 2013

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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.