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

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.

Question by:bourbaki
    LVL 5

    Expert Comment

           p = &i;
        *pp = p;           <<-- i think this line should be pp = &p;
    LVL 45

    Expert Comment


    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,

    Author Comment

    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;

    LVL 45

    Accepted Solution


    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.

    911 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now