NO

Author Topic: error - Undeclared identifier 'TRUE' after moving  (Read 20017 times)

vedro-compota

  • Guest
error - Undeclared identifier 'TRUE' after moving
« on: December 20, 2011, 09:29:23 AM »
Hi C athlets!)

Please tell me  - where can be problem (except my head and hands  :)))) in this situation  -
If i move one custom function in additional C  file from  the main one - i get error  =
Quote
: error #2048: Undeclared identifier 'TRUE'.

for line  =
Code: [Select]
   int result= TRUE;

both main and additional  files  have includes =

Code: [Select]
#include <stdio.h>
#include <stdlib.h>

if use this line in main.c  - all will be ok,

big thanks in advance)


CommonTater

  • Guest
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #1 on: December 20, 2011, 10:15:15 AM »
Post your code...

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #2 on: December 20, 2011, 10:52:50 AM »
Do you have the same include files in both sources?
best regards
 Alex ;)

vedro-compota

  • Guest
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #3 on: December 20, 2011, 02:54:01 PM »
Quote
Do you have the same include files in both sources?
AlexN - yes - I have - without it compiler show much more errors.....

CommonTater
,  i've added project to this post  - code is quite big
« Last Edit: December 20, 2011, 03:09:47 PM by vedro-compota »

vedro-compota

  • Guest
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #4 on: December 20, 2011, 03:18:17 PM »
CommonTater , I'll publish only parts -the whole project you can see in attachments to the previous post

the entry file (with main() func)  =
Code: [Select]
#include <stdio.h>
#include <stdlib.h>

#include "comlib.h"
#include "task1.h"
int main()
{   int result= TRUE;
     os_founders_respect();
mainmenu();


return 0;
   
}
.............


the second source =

Code: [Select]
#include<stdio.h>
#include <stdlib.h>

#include "comlib.h"
#include "task1.h"




int task1standard(void)
{
//FILE *file1, *file2,  *file3;

    int result= TRUE;
    char **arr,*ftext,**arr1,**arr2;
    FILE *fp,*fp2,*rfp;
..................
}

additional comlib.c ( custom funcs for general purpose) =
 
Code: [Select]
#include <stdio.h>
#include <stdlib.h>

#include "comlib.h"




 int tdarrs_cmp(char **arr1,char **arr2, FILE *rfp)
 {  /* */


   int k=0;
   int n1=1;
   int n2=1;
   if (!rfp) rfp=fopen("compRESULT.txt","w");
   
   printf("\n\n[%s]\n", "...comparation of two two-demision arrays showing is started...");
« Last Edit: December 20, 2011, 03:40:02 PM by vedro-compota »

Offline DMac

  • Member
  • *
  • Posts: 272
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #5 on: December 20, 2011, 04:58:30 PM »
Privyet Mr. Vedro,

The C spec does not contain a boolean type and does not have definitions for TRUE or FALSE as such.  The Windows API does, however, define these types.

This piece of code in task1code.c
Code: [Select]
#if defined(_WIN32) || defined (_WIN64)
#include <windows.h>
#define  IN_WINDOWS 1
#endif
provides that file with the definition of TRUE.
If you want to use the symbol TRUE but you do not want to include windows.h then you should add the following to comlib.h which is included in each of your source files.
Code: [Select]
typedef int BOOL;

#ifndef FALSE
#define FALSE  0
#endif

#ifndef TRUE
#define TRUE  1
#endif

Udache Vam :D
No one cares how much you know,
until they know how much you care.

vedro-compota

  • Guest
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #6 on: December 20, 2011, 07:40:25 PM »
 privet  i tebe , DMac ) but why it work in source file which contain the main() functions - because  "Windows API does" ?

CommonTater

  • Guest
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #7 on: December 20, 2011, 07:59:04 PM »
It works in your main file because you used #include <windows> in it... but nowhere else.

Each source file is a separate compilation unit... the compiler builds them file by file, creating obj files for each.  If you want to include a header in all your files, you have to include it in all your files... either that or make a global header and include that in all your files... Either way the compiler only knows what you tell it... one file at a time.



vedro-compota

  • Guest
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #8 on: December 20, 2011, 08:19:10 PM »
i don't want to include headers in each file - but how  be  otherwise ? compiler shows many error of "undecleared" type  -
for example -  @ Undeclared identifier 'NULL' @

CommonTater

  • Guest
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #9 on: December 20, 2011, 08:34:48 PM »
It's not about what YOU want to do... it's about what needs to be done to make it work.

I've never yet written a C source file that does not include at least a couple of headers.

Remember... when you are talking to C (through source code) you are giving instructions to a complete idiot.  It will do exactly what you tell it, in the order you tell it... it won't care how wrong it is and it won't remember anything it's done.  You have to tell it *everything* in little baby steps or it will not understand you.





vedro-compota

  • Guest
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #10 on: December 20, 2011, 08:44:18 PM »
Quote
Remember... when you are talking to C (through source code) you are giving instructions to a complete idiot.  It will do exactly what you tell it, in the order you tell it... it won't care how wrong it is and it won't remember anything it's done.  You have to tell it *everything* in little baby steps or it will not understand you.
CommonTater  "I" know this!
Tell me  - how to avoid the multiple including of  equal headers ?!
all that you tell me   - is right - but  i don't understand this  -
if compiler build each file separately - does it mean that we should include all needed headers in all source files??

CommonTater

  • Guest
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #11 on: December 20, 2011, 08:46:27 PM »
[Tell me  - how to avoid the multiple including of  equal headers ?!
all that you tell me   - is right - but  i don't understand this  -
if compiler build each file separately - does it mean that we should include all needed headers in all source files??

Yes, that's exactly what it means... and that is why we use include guards.
 
Remember that project tree I showed you...  Here are some samples from the files in that project...
B_Main.c
Code: [Select]
// Main entry and gui code
#define WIN32_DEFAULT_LIBS
#define UNICODE
#define _UNICODE
// winapi
#include <windows.h>
#include <commctrl.h>
#include <shlwapi.h>
// private
#include <errorx.h>
#include <EZSplit.h>
// project
#include "B_Main.h"
#include "B_TreeView.h"
#include "B_ListView.h"
#include "B_Setup.h"

B_Setup.c
Code: [Select]
// Setup functions
// windows api
#define WIN32_DEFAULT_LIBS
#define UNICODE
#define _UNICODE
// windows
#include <windows.h>
#include <shlwapi.h>
// project
#include "B_Main.h"

B_Listview.c
Code: [Select]
// List View Functions
#define WIN32_DEFAULT_LIBS
#define UNICODE
#define _UNICODE
// winapi
#include <windows.h>
#include <commctrl.h>
#include <shlwapi.h>
// C-99
#include <wchar.h>
// project
#include "B_Main.h"
#include "B_LanEnum.h"

B_Treeview.c
Code: [Select]
// Tree View functions
#define WIN32_DEFAULT_LIBS
#define UNICODE
#define _UNICODE
// winapi
#include <windows.h>
#include <commctrl.h>
#include <shlwapi.h>
// private
#include <ErrorX.h>
// C-99
#include <wchar.h>
// project
#include "B_Main.h"
#include "B_ListView.h"
#include "B_LanEnum.h"

Getting the idea?

 
« Last Edit: December 20, 2011, 08:54:50 PM by CommonTater »

vedro-compota

  • Guest
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #12 on: December 20, 2011, 08:53:05 PM »
ok . as I see - it's possible to use #include in header itself =
Code: [Select]
#ifndef  TASK1_H
#define  TASK1_H

#include "comlib.h"
int task1standard(void);
int task1custom(void);
int testme(void);

#endif

 is it a good practice ??

Quote
Getting the idea?
yeah - it's complex example - many includes in each source file....
« Last Edit: December 20, 2011, 09:01:25 PM by vedro-compota »

CommonTater

  • Guest
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #13 on: December 20, 2011, 09:01:37 PM »
ok . as I see - it's possible to use #include in header itself =

Yes it 's possible... but you should only do that if something in the header (constants, types, etc) need the included header.

for example... Here's a segment of one of the headers from that project...
Code: [Select]
#ifndef B_TREEVIEW_H
#define B_TREEVIEW_H
 
#include <windows.h>
#include <commctrl.h>
 
VOID tvRenameFavorite(HWND tvCtrl);
BOOL tvStartLabelEdit(HWND tvCtrl);
BOOL tvEndLabelEdit(LPNMTVDISPINFO NewItem);
BOOL tvExpandBranch(LPNMTREEVIEW Item);
BOOL tvCloseBranch(LPNMTREEVIEW Item);

I've included windows.h  for the HWND typedef and commctrl.h because of typedefs needed by the function prototypes.... but only those needed by the header itself.  If the header would work without the includes, I would not have them in there.
 


 

CommonTater

  • Guest
Re: error - Undeclared identifier 'TRUE' after moving
« Reply #14 on: December 20, 2011, 09:03:46 PM »
yeah - it's complex example - many includes in each source file....

That's the way it goes... each fle stands by itself, starting from nothing.
 
What you don't see, because of the way POIDE compiles from it's .ppj files is that the compiler is started for each new file and exits when done... everything is reset to zilch every time.