Hi there))
Guys , there's a problem , which i can't solve myself.
I have file (winfunc.h) here it's =
#ifndef TASK1_H
#define TASK1_H
int task1standard(void);
int task1custom(void);
int testme(void);
int task1comp (FILE* , FILE* , FILE* ); // error #2161: Extraneous old-style parameter list. + error #2001: Syntax error: expected ')' but found '*'.
#endif
compiler shows erroes =
QuoteBuilding winfunc.obj.
D:\Bu-Bu\training programs\my\C\OS\t1\task1.h(7): error #2001: Syntax error: expected ')' but found '*'.
D:\Bu-Bu\training programs\my\C\OS\t1\task1.h(7): error #2161: Extraneous old-style parameter list.
D:\Bu-Bu\training programs\my\C\OS\t1\winfunc.h(10): warning #1039: [ISO] No newline at end of file.
*** Error code: 1 ***
for line =
int task1comp (FILE* , FILE* , FILE* );
the task1comp has such realisation =
int task1comp(FILE* fp,FILE* fp2,FILE* rfp)
{
char **arr1,**arr2;
arr1 = tfile_to_tdarr(fp);
arr2 = tfile_to_tdarr(fp2);
tdarr_show(arr1);
tdarr_show(arr2);
tdarrs_cmp(arr1,arr2,rfp);
fclose(fp);
fclose(fp2);
fclose(rfp);
return 0;
}
I've attached the whole project to this post.
what's wrong here?
big thanks in advance )
Try putting the variable names in your header's prototype...
Also you need to include stdio.h in your header since FILE is defined in it.
#ifndef TASK1_H
#define TASK1_H
#include <stdio.h>
int task1standard(void);
int task1custom(void);
int testme(void);
int task1comp(FILE* fp,FILE* fp2,FILE* rfp);
#endif
QuoteAlso you need to include stdio.h in your header since FILE is defined in it.
CommonTater , this have helped! thank you!!)) . but where's the compiler's logic ? -
.h files (as i know) isn't compiled by compiler but should be only included in that section of .c file - in which .c file has #include directive.
So my task1.c starts with =
/* функции ниж*/
#include<stdio.h>
#include <stdlib.h> // <stdlib.h> is before header
#include "comlib.h"
#include "task1.h"// HEADER
#include <windows.h>
#include "winfunc.h"// my windows func
so as a result we have task1.c with included <stdlib.h> without need of including <stdlib.h> in task1.h
but compiler show error which as if it compiles task1.h separately.
why is it so?
First of all, header files are not compiled... they are simply included into the source as text files. Listing headers does not guarantee they will be added to the resulting overall source code seen by the compiler in the order they are listed... It only guarantees they will be included *someplace*.
You should never count on your main file to make things available to a header... it's quite the other way around, the header should be making things available to your .c file.
Quote......the header should be making things available to your .c file.
ok. do you words mean that in my case compiler simply firstly checks .h file and include it into sourse text file only after checking? but checking was
failed so (because i hadn't stdio.h in my task1.h file) - i have get the error.....
do i understand you?
Yes headers are checked before inclusion.
hint: You get error reports about them... right?
However, that isn't the meaning of the bit you quoted.
You commented that you should not need stdio.h in the header since it was included in the .c file... that's backwards... you should not have your main file making stdio.h available to your header.
>>>>hint: You get error reports about them... right?
about headers? yes. like =
>>>>D:\Bu-Bu\training programs\my\C\OS\t1\task1.h(7): error #2161: Extraneous old-style parameter list.
_____________
>>>>you should not have your main file making stdio.h available to your header.
how can i make stdio.h not available for header in my main file ?
Quote from: vedro-compota on January 17, 2012, 06:56:40 PM
>>>>hint: You get error reports about them... right?
about headers? yes. like =
>>>>D:\Bu-Bu\training programs\my\C\OS\t1\task1.h(7): error #2161: Extraneous old-style parameter list.
That's why I told you to put the variable names in the header file...
See my first reply in this thread.
Quote
>>>>you should not have your main file making stdio.h available to your header.
how can i make stdio.h not available for header in my main file ?
You don't need to worry about that.
Just include stuff where you need to... let the include guards take care of it for you.
To phrase it another way....
The .c file can rely on the header.
The header should not rely on the .c file.