473,748 Members | 2,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2045

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_Keit h) 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
2202
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 possibilities and decided to insert a cout in the loop that gave the percentage that had been completed. The program worked, but I soon realized it would take almost a month of execution time for it to finish. I figured the cout was slowing the...
14
2735
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= 0; char *aString = 0; char *bString = 0; MY_NUM *a;
20
1514
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; strncpy(buf2,*(argv+1),sizeof(buf2));
5
1987
by: Kuku | last post by:
My Program is crashing at strupr(e2.n); int main() { struct emp {
3
3248
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 working VB6 version. I have tried changing the returned buffer datatype from string to object. The program does not crash (no work) if I remove the ref argument on the 2nd argument within the ReadFile API ('psBuffer'). A quick API sniffer revealed:...
17
6442
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
1464
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 has complained about it crashing. The program seems to run fine.
41
2458
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 an exe, not from the Debug option. If I try to launch the debug on the crashing program, it'll close before the debugger opens. Any suggestions as to how I should proceed? Thanks in advance.
3
2513
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 verify that the filename has a .txt extension. The code below works great as long as a '.' is entered regardless of the extension, but if no '.' is entered into the file name the program crashes. I'm sure it has to do with the fact the program is...
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9386
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8255
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.