Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 19:25

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Preprocessor directives Help!

Discussion on Preprocessor directives Help! within the C/C++ forum part of the Coders Den category.

Closed Thread
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 166
Preprocessor directives Help!

Hi guys i'm trying to code a handle to a file so that i can write to it, i'm a bit confused cause i don't know if i can make it work that way.

First i tried this way:

It won't compile anyway..

Then i try to process everything together like this:

Will compile but, will make stack error and won't create the file :C

So, if i use the first example and remove the #if and replace it in the main function will work, but i'll have to declare a FILE* handle, and that crap and i don't want to do it...

Is it posible to make it work in preprocessing section or not??

elmarcia is offline  
Old 03/21/2015, 17:51   #2
 
elite*gold: 0
Join Date: Feb 2009
Posts: 1,137
Received Thanks: 572
Well this doesn't make any sense either, the Preprocessor works before the Real Compilation, so Checking if a file exists while Compiling 1. Doesn't make any sense, because lets say that the program is compiled, than you got a handle as a constant in your program. Even if you change your file, or restart your pc, it will have the same handle, it just can't work
2. It doesn't work, because preprocessing is done before the Compilation, using C++ code in this statements just can't work well because the preprocessor doesnt work with C++ commands.


here a little example, try this little program:
Code:
#include <iostream>

#define FILENAME "/data.dat"
#define EXIST (fopen(FILENAME,"r") == NULL)?"true":"false"  //Exist or not

int main()
{
  std::cout << EXIST;

  return 0;
}
the result is 1%
warfley is offline  
Thanks
1 User
Old 03/21/2015, 18:16   #3
 
elite*gold: 0
Join Date: Apr 2011
Posts: 363
Received Thanks: 166
Thx dude, i really messed up with that haha. I will continue reading about that before doing such things like these... :c

#closerequest
elmarcia is offline  
Old 03/21/2015, 18:57   #4

 
snow's Avatar
 
elite*gold: 724
Join Date: Mar 2011
Posts: 10,480
Received Thanks: 3,319
#closed (on request)
snow is offline  
Closed Thread




All times are GMT +2. The time now is 19:25.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.