Like Tree5Likes

[C malloc/free] ~ free-ing the allocated memory gives c0000005 Windows error

This is a discussion on [C malloc/free] ~ free-ing the allocated memory gives c0000005 Windows error within the C Programming forums, part of the General Programming Boards category; Originally Posted by Spiegel The question is: is it just the compiler I'm using, or it's an official C rule, ...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,589
    Quote Originally Posted by Spiegel
    The question is: is it just the compiler I'm using, or it's an official C rule, that I cant use "_" for "typedef" names?
    No, there is no such rule. However, there are two rules (from C99 Clause 7.1.3 Paragraph 1) that say:
    • All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.
    • All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces.

    A simple rule of thumb is just to avoid naming things with names that begin with an underscore.

    Quote Originally Posted by Spiegel
    The name given to this typedef was something like "abc_def" and I was getting an error about something like an "incomplete statement". Banged my head really hard for quite a while, before trying to change the typedef name by taking out the freaking "_". After that, everything worked great.
    The thing is, "something like" is not convincing. For example, compile this program:
    Code:
    #include <stdio.h>
    
    typedef struct X {
        double a;
        int b;
    } abc_def;
    
    int main(void)
    {
        abc_def x = {1.2, 3};
        printf("%f %d\n", x.a, x.b);
        return 0;
    }
    What error do you get?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User Spiegel's Avatar
    Join Date
    Jul 2012
    Location
    Italy
    Posts
    14

    Unhappy

    Quote Originally Posted by laserlight View Post
    No, there is no such rule. However, there are two rules (from C99 Clause 7.1.3 Paragraph 1) that say:
    • All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.
    • All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces.

    A simple rule of thumb is just to avoid naming things with names that begin with an underscore.


    The thing is, "something like" is not convincing. For example, compile this program:
    Code:
    #include <stdio.h>
    
    typedef struct X {
        double a;
        int b;
    } abc_def;
    
    int main(void)
    {
        abc_def x = {1.2, 3};
        printf("%f %d\n", x.a, x.b);
        return 0;
    }
    What error do you get?

    Tried. And gives no error.

    I've also tried to write it my way (noobie way) and it still gives no error. I surrender, I dont know why I got the error before but not now. =p
    What I know is that the name had a "_" in the middle and stopped giving the error after I took the "_" off.

    Code:
    #include <stdio.h>
    
    typedef struct X { //YOUR WAY
        double a;
        int b;
    } abc_def;
    
    int main(void)
    {
        abc_def x = {1.2, 3};
        printf("%f %d\n", x.a, x.b);
    
        struct y_j //MY WAY
        {
            int a;
            int b;
        };
    
        typedef struct y_j z_w;
    
        z_w * a;
    
        return 0;
    }
    Last edited by Spiegel; 12-28-2012 at 03:14 PM. Reason: Awful formatting

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to properly free a pointer and its allocated memory
    By yuzhangoscar in forum C Programming
    Replies: 2
    Last Post: 09-16-2008, 06:26 AM
  2. Can you free memory allocated by a std::string?
    By BrianK in forum C++ Programming
    Replies: 17
    Last Post: 05-15-2008, 11:57 AM
  3. Malloc - Free giving double free or corruption error
    By andrew.bolster in forum C Programming
    Replies: 2
    Last Post: 11-02-2007, 06:22 AM
  4. Will free() clean up this allocated memory?
    By simguy in forum C Programming
    Replies: 3
    Last Post: 01-18-2007, 04:21 PM
  5. free allocated memory on interrupts
    By scrappy in forum C Programming
    Replies: 4
    Last Post: 02-20-2004, 10:13 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21