[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Why there are not error when use Turbor c++ 3.0 to compile and run a c file and error with vc and gcc?

Posted on 2004-10-29
4
Medium Priority
?
208 Views
Last Modified: 2010-04-15
There is a C file as following:
/***************************/
// C file
#include <stdio.h>
int main()
{
    int i, *p, **pp;
    i = 9;
    p = &i;
    *pp = p;
    printf("%d",**pp);
}
/***************************/

Using Turbor c++ 3.0 to compile the file, get a output 9.
Using vc under windows xp or gcc under linux, there is a running error.
why?

thanks.
0
Comment
Question by:bourbaki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:van_dy
ID: 12444459
       p = &i;
    *pp = p;           <<-- i think this line should be pp = &p;
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 12444471

Luck of the draw, mostly.

The line "*pp = p;" is in error.  The TurboC compiled program is storing the value at a non-critical location so no abort occurs.  The code generated by the vc and gcc compilers result in the data being written to protected memory which is causing the error.

You haven't assigne a value to *pp* yet, so you cannot dereference it.  I suspect that what you want to do is

  pp = &p;


Good Luck,
Kent
0
 

Author Comment

by:bourbaki
ID: 12450735
hi Kdo

i don't know what the mean is "non-critical"? Can you explanation?

btw: My programme is written for test so it is exactly
*pp = p;

thanks.
0
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 150 total points
ID: 12457248

If you write to a seemingly random address in memory, one of three things will happen.

*) You'll overwrite "critical" memory, in which case your program will hang, segfault, the PC will lock up, etc.

*) You'll overwrite you own data (perhaps the wrong location in an array) which causes your program to give strange answers.

*)  You'll overwrite a cell that isn't being used so nothing bad will happen.  However, changing something else in your program changes the program size so this "random write" can suddenly become critical.


Kent
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question