473,385 Members | 1,872 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,385 software developers and data experts.

Pragma

How can i use a pragma directive in order to show warning by compiler when a variable is declared twice.. That is

class a
{
int b;
void f()
{
int b;
}
};

although it is getting compiled without warning.
Dec 8 '11 #1

✓ answered by Banfa

pragmas are entirely compiler dependent, you only have what your compiler provides.

However in general no compiler provides a way to add warnings. If the compiler is able to do it it will already be a part of the compiler.

As weaknessforcats says your problem is that you have defined two variables at different scopes but because they have the same name the one in a::f hides the member declaration in a.

Static analysis tools, such as PCLint will pick up this sort of error.

2 1005
weaknessforcats
9,208 Expert Mod 8TB
Your variable is not defined twice.

There are two variables. They have the same name which is OK because the scope is different.
Dec 8 '11 #2
Banfa
9,065 Expert Mod 8TB
pragmas are entirely compiler dependent, you only have what your compiler provides.

However in general no compiler provides a way to add warnings. If the compiler is able to do it it will already be a part of the compiler.

As weaknessforcats says your problem is that you have defined two variables at different scopes but because they have the same name the one in a::f hides the member declaration in a.

Static analysis tools, such as PCLint will pick up this sort of error.
Dec 9 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Steven T. Hatton | last post by:
Stroustrup says this: http://www.research.att.com/~bs/bs_faq2.html#macro "So, what's wrong with using macros?" "And yes, I do know that there are things known as macros that doesn't...
6
by: Shri | last post by:
Can anybody tell me where i can find a detailed document on #pragma .... --shri
1
by: Gustavo L. Fabro | last post by:
Greetings! Going directly to the point: myclass.h: //-------------------------------------- #pragma managed //Forward declaration
11
by: ramu | last post by:
HI, Can anyone tell me about pragma? And can u give an example of how to use it?
15
by: muttaa | last post by:
Hello all, I'm a beginner in C...May i like to know the difference between a #pragma and a #define.... Also,yet i'm unclear what a pragma is all about as i can find topics on it only in...
8
by: rwen2012 | last post by:
Hi, guys, I am confused with the preprocessor instruction #pragma. What does the #pragma mean? and what does this mean as follow? ==================== #pragma intterupt Timer...
5
by: venkat | last post by:
Hi, I have come across the a pragma definition " #pragma switch direct ". I don't know any thing about pragma's. Even i when i search through google not getting exact information. what does...
26
by: Rick | last post by:
I'm told that "#pragma once" has made it into the ISO standard for either C or C++. I can't find any reference to that anywhere. If it's true, do any of you have a reference I can use? ...
2
by: aleemakhtar1 | last post by:
wat is use of pragma directive in embedded sys ??
0
debasisdas
by: debasisdas | last post by:
PRAGMA:-Signifies that the statement is a pragma (compiler directive). Pragmas are processed at compile time, not at run time. They pass information to the compiler. A pragma is an instruction to...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.