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 07:54 AM.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    5,969

    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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.5.4)

  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,449

    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 a Codeguru.com survey!


On-Demand Webinars (sponsored)