NO

Author Topic: Error in .h file  (Read 7341 times)

vedro-compota

  • Guest
Error in .h file
« on: January 17, 2012, 02:16:37 PM »
Hi there))

Guys , there's a problem , which i can't solve myself.

I have file (winfunc.h) here it's =
Code: [Select]
#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 =
Quote
Building 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 =
Code: [Select]
int task1comp (FILE* , FILE* , FILE* );the task1comp has such realisation =
Code: [Select]
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 )

CommonTater

  • Guest
Re: Error in .h file
« Reply #1 on: January 17, 2012, 02:54:42 PM »
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.

Code: [Select]
#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



vedro-compota

  • Guest
Re: Error in .h file
« Reply #2 on: January 17, 2012, 03:57:29 PM »
Quote
Also 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 =
Code: [Select]
/* функции ниж*/
#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?
« Last Edit: January 17, 2012, 03:59:05 PM by vedro-compota »

CommonTater

  • Guest
Re: Error in .h file
« Reply #3 on: January 17, 2012, 04:27:44 PM »
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.

« Last Edit: January 17, 2012, 04:30:55 PM by CommonTater »

vedro-compota

  • Guest
Re: Error in .h file
« Reply #4 on: January 17, 2012, 04:45:37 PM »
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?

CommonTater

  • Guest
Re: Error in .h file
« Reply #5 on: January 17, 2012, 04:49:41 PM »
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.
« Last Edit: January 17, 2012, 04:54:21 PM by CommonTater »

vedro-compota

  • Guest
Re: Error in .h file
« Reply #6 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.
_____________
>>>>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 ?


CommonTater

  • Guest
Re: Error in .h file
« Reply #7 on: January 17, 2012, 07:24:44 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.


 
« Last Edit: January 17, 2012, 07:27:58 PM by CommonTater »