473,413 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

conditional compile...

hello all,

i wrote the small program below to practice conditional compiling. if i
define MYSYMBOL then everthing works fine, but when i comment MYSYMBOL
gcc gives the following message:
cnd_compile01.c:4:2: error: #error "Error"
cnd_compile01.c:1: warning: ISO C forbids an empty source file

i cant understand the warning and how to eliminate it? i tried placing
some dummy comment but still the same warning.

also why is compiler printing error twice. it looks ugly. is there a
way to make it print error once only?

thanks.

code:
/* #define MYSYMBOL 1 */

#if MYSYMBOL != 1
#error "Error"
#else

#include <stdio.h>
main() { puts("hello"); }

#endif
Nov 30 '07 #1
3 3254
naunetr wrote:
hello all,

i wrote the small program below to practice conditional compiling. if i
define MYSYMBOL then everthing works fine, but when i comment MYSYMBOL
gcc gives the following message:
cnd_compile01.c:4:2: error: #error "Error"
cnd_compile01.c:1: warning: ISO C forbids an empty source file

i cant understand the warning and how to eliminate it? i tried placing
some dummy comment but still the same warning.
You need real code. A static declaration will do; comments won't.
also why is compiler printing error twice. it looks ugly. is there a
way to make it print error once only?
Pass [1]. But who cares? The way to stop it printing `error` twice is to
stop it printing `error` at all. If there's a real error error, the
repeated text is likely to be the least of your problems.

[1] If there is, it will be compiler specific. gcc has many many command-
line options, many of which control diagnostic reports.

--
Chris "it was deliberate" Dollin

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Nov 30 '07 #2
naunetr wrote:
>
hello all,

i wrote the small program below to practice conditional compiling.
if i
define MYSYMBOL then everthing works fine, but when i comment MYSYMBOL
gcc gives the following message:
cnd_compile01.c:4:2: error: #error "Error"
cnd_compile01.c:1: warning: ISO C forbids an empty source file

i cant understand the warning and how to eliminate it? i tried placing
some dummy comment but still the same warning.
It means that with MYSYMBOL commented out, this:
#error "Error"
becomes your whole program,
and that's not enough of a program to compile.

code:
/* #define MYSYMBOL 1 */

#if MYSYMBOL != 1
#error "Error"
#else

#include <stdio.h>
main() { puts("hello"); }

#endif
--
pete
Nov 30 '07 #3
On Fri, 30 Nov 2007 19:57:40 +0530, naunetr <na*****@gmail.comwrote
in comp.lang.c:
hello all,

i wrote the small program below to practice conditional compiling. if i
define MYSYMBOL then everthing works fine, but when i comment MYSYMBOL
gcc gives the following message:
cnd_compile01.c:4:2: error: #error "Error"
cnd_compile01.c:1: warning: ISO C forbids an empty source file

i cant understand the warning and how to eliminate it? i tried placing
some dummy comment but still the same warning.

also why is compiler printing error twice. it looks ugly. is there a
way to make it print error once only?
The compiler is outputting two different diagnostic messages because
there are two different issues with your program.

thanks.

code:
/* #define MYSYMBOL 1 */

#if MYSYMBOL != 1
#error "Error"
#else

#include <stdio.h>
main() { puts("hello"); }

#endif
To add detail to Pete's explanation...

When MYSYMBOL is not defined to 1, the preprocessor eliminates
everything and the compiler only sees:

#error "Error"

....as the entire translation unit. C requires that every translation
unit requires at least one external definition, and yours does not
have one. That's the second diagnostic, the one referring to line 1,
although the text of the diagnostic is misleading.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Dec 1 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Steven T. Hatton | last post by:
I've made no secret of the fact that I really dislike the C preprocessor in C++. No aspect of the language has caused me more trouble. No aspect of the language has cause more code I've read to be...
13
by: Andrew | last post by:
I use conditional compiler constants, set through the VBA IDE in Tools, <projectname> Properties, that I refer to throughout my code to control which code is used during development, and which...
1
by: chris han | last post by:
Hi, all, I'm trying to use Conditional Compilation Statements in my code. using System; #define DEBUG public class MyClass { public static void Main() {
12
by: wanghz | last post by:
Hi, Could I ask some questions about the conditional compilaion? Suppose I have three simple files: a.c, b.c and c.h /* --------a.c--------- */ #include <stdio.h> #include "c.h" int...
2
by: FireStarter | last post by:
Guys, in the code that follows, why does the method F() still compile, even if DBG is undefined? Inside method G(), the code inside <#if DBG> does not compile (notice that I can write whatever I...
7
by: John Dolinka | last post by:
I have a project of several files with #defines to setup a conditional compile. I would like to put these #defines in a single file and change the conditional compile from this one file with the...
10
by: John Smith | last post by:
After reading C# documentation the Conditional attribute seemed the way to go, but after inspecting the IL it seems those methods are still there and I imagine the CLR removes them. Using #if DEBUG...
6
by: Marc Jennings | last post by:
Hi there, I am trying to get some conditional functionality into some of my apps. I can use the format : private void doStuff() { //do something }
4
by: David Veeneman | last post by:
I'm creating several public properties in a class that I will use exclusively for testing purposes. In a Debug compile, I want these properties to be included in the compile, but I want them...
15
by: Nicholas M. Makin | last post by:
I was just thinking that I understood the conditional operator when I coded the following expecting it to fail: int a= 10, b= 20, c= 0; ((a < b) ? a : b) = c; // a=0 a=20; b= 10; ((a < b) ? a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.