problem with header files

Started by lasm, March 24, 2011, 09:22:56 AM

Previous topic - Next topic

lasm

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. #include "bufferHandler.h"

I have this protypes on the header file:

void setupBufferStore();
MultiBuffer *getMultiBuffer();
int GetBufferOnQueue(int, MultiBuffer pBuffer);


and I declared in bufferHandler.c the fuctions:

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


   

TimoVJL

void setupBufferStore(void);
MultiBuffer *getMultiBuffer(void);
int GetBufferOnQueue(int, MultiBuffer pBuffer);

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

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

Stefan Pendl

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

Hi Stefan,
So this means that good practice is to always use (void) instead of ()?
Best Regards
                 Luis

CommonTater

Quote from: lasm 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

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!)