alloc.h
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: alloc.h

  1. #1
    Join Date
    Jul 2013
    Posts
    30

    alloc.h

    Has anyone used CodeBlocks (MingW plugins) here? I can't seem to use the alloc.h library. When I try to compile my code, the compiler can't seem to find the alloc.h...

    \Desktop\Proj\LinkedList\main.c|4|error: alloc.h: No such file or directory|
    \Desktop\Proj\LinkedList\main.c||In function 'insertData':|
    \Desktop\Proj\LinkedList\main.c|84|warning: incompatible implicit declaration of built-in function 'malloc'|
    \Desktop\Proj\LinkedList\main.c||In function 'delete':|
    \Desktop\Proj\LinkedList\main.c|114|warning: incompatible implicit declaration of built-in function 'free'|
    ||=== Build finished: 1 errors, 2 warnings ===|
    I tried compiling the code using Turbo C (in DOSBox), and at first it was sending out a "Declaration not allowed here error":

    Code:
    void save() {
    	int i;
    	LIST *p;
    	p = L;
    	FILE *fp;
    	fp = fopen("/mit594.dbf", "w+");
    	
    	while (p != NULL) {
    		fprintf(fp,"%d\n",L->x);
    		p=p->next;
    	}
    	fclose(fp);
    }
    I tried moving the FILE *fp line to the first line in the code and it worked. Can someone explain to me why this happened?
    Last edited by riechan; August 17th, 2013 at 06:54 AM.

  2. #2
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,453

    Re: alloc.h

    In Turbo c, definitions have to come at the beginning of the function before statements. p = L; is a statement not a definition so no further definitions are allowed after this statement. That is why when you moved FILe *fp above p = L it worked.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  3. #3
    Join Date
    Jul 2013
    Posts
    30

    Re: alloc.h

    I see. Thanks for clearing that up 2kaud!

  4. #4
    Join Date
    Apr 1999
    Posts
    27,429

    Re: alloc.h

    Quote Originally Posted by 2kaud View Post
    In Turbo c, definitions have to come at the beginning of the function before statements. p = L; is a statement not a definition so no further definitions are allowed after this statement. That is why when you moved FILe *fp above p = L it worked.
    Actually those are the rules of ANSI 'C'. Declarations must occur before executable statements. You would get the same error if you compiled a .C file in Visual Studio and made the same mistake.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center