NO

Author Topic: problem with header files  (Read 3513 times)

lasm

  • Guest
problem with header files
« on: March 24, 2011, 09:22:56 AM »
Hi Guys,
I just started using Pelles C, I been using C for a while now to program my ARM processors with another IDE. Manlly I plan to use Pelles C to test some of the more complicated parts of the programs as a sort of test bed.
I transferred a bit of code from the other IDE which is Eclipse based and with GCC compiler, and i am having a few problems with the function prototypes.

So, I have a Header file called "bufferHandler.h", I added an include on the C file bufferHandler.c and in main.c i.e.
Code: [Select]
#include "bufferHandler.h"
I have this protypes on the header file:
Code: [Select]
void setupBufferStore();
MultiBuffer *getMultiBuffer();
int GetBufferOnQueue(int, MultiBuffer pBuffer);

and I declared in bufferHandler.c the fuctions:
Code: [Select]
void setupBufferStore()
{
int i = 0;
for(i = 0; i < NUMBEROFBUFFERS;i++)
{
pFreeBuffers[i] = &bufferStore[i];
}
}

MultiBuffer *getMultiBuffer()
{
if (freeBuffersCount != 0)
{
freeBuffersCount--; // ---this may need checking.----
return *pFreeBuffers[freeBuffersCount]; // return the pointer to the available buffer
// that is stored at this array position
}

else
{
return null;
}

}



When I compile I get the errors:

C:\Personal\CProg\MyCode\Pointert150311\bufferHandler.c(61): warning #2027: Missing prototype for 'setupBufferStore'.
C:\Personal\CProg\MyCode\Pointert150311\bufferHandler.c(85): warning #2027: Missing prototype for 'getMultiBuffer'.

I know I have an error in getMultiBuffer() as I need to return a null pointer and I am actually returning NULL, but apart from that, I just can not see what the problem is.
Any help welcomed.
Best Regards
                 Luis


   

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: problem with header files
« Reply #1 on: March 24, 2011, 10:22:11 AM »
Code: [Select]
void setupBufferStore(void);
MultiBuffer *getMultiBuffer(void);
int GetBufferOnQueue(int, MultiBuffer pBuffer);
Code: [Select]
void setupBufferStore(void)
{
int i = 0;
for(i = 0; i < NUMBEROFBUFFERS;i++)
{
pFreeBuffers[i] = &bufferStore[i];
}
}

MultiBuffer *getMultiBuffer(void)
{
if (freeBuffersCount != 0)
{
freeBuffersCount--; // ---this may need checking.----
return *pFreeBuffers[freeBuffersCount]; // return the pointer to the available buffer
// that is stored at this array position
}

else
{
return null;
}

}
May the source be with you

lasm

  • Guest
Re: problem with header files
« Reply #2 on: March 24, 2011, 10:30:37 AM »
Hi timovjl,
That seems to work, but i can't really understand it, I never had to write "(void)" in any of the compilers I used before.
Best Regards
                    Luis

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: problem with header files
« Reply #3 on: March 24, 2011, 10:38:09 AM »
Some allow the developer to get lazy and add the missing void internally on their own.
---
Stefan

Proud member of the UltraDefrag Development Team

lasm

  • Guest
Re: problem with header files
« Reply #4 on: March 24, 2011, 10:41:48 AM »
Hi Stefan,
So this means that good practice is to always use (void) instead of ()?
Best Regards
                 Luis

CommonTater

  • Guest
Re: problem with header files
« Reply #5 on: March 24, 2011, 02:48:57 PM »
Hi Stefan,
So this means that good practice is to always use (void) instead of ()?
Best Regards
                 Luis

FWIW... in C99 ... function()  indicates a function that takes any number of parameters where function(void) indicates a function that takes no parameters.  Pelles C is (thankfully) rather strict about that.

(Hi Timo!)