473,402 Members | 2,050 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,402 software developers and data experts.

Reinitialization of same variable

1
When I reintialize a variable, CL compiler issues the following error.

---- Program ---
int siVar=10 ;
int siVar=10;
---------------------

error C2374: 'siVar' : redefinition; multiple initialization
test.c(1) : see declaration of 'siVar'

Can anyone tell me whether it is as per ANSI C specification.

If yes, could you please give me the snip from ANSI C specification,(ISO/IEC 9899:1999)


Thanks in advance :-)
Jul 27 '07 #1
4 1696
ravenspoint
111 100+
When I reintialize a variable, CL compiler issues the following error.

---- Program ---
int siVar=10 ;
int siVar=10;
---------------------

error C2374: 'siVar' : redefinition; multiple initialization
test.c(1) : see declaration of 'siVar'
You have told the compiler to store siVar in two different places. It rightly refuses.

Declare the variable, with or without an initiazation, just once. Then you can only change its value.
Jul 27 '07 #2
JosAH
11,448 Expert 8TB
You have told the compiler to store siVar in two different places. It rightly refuses.

Declare the variable, with or without an initiazation, just once. Then you can only change its value.
No, that's not how thing work:you can declare a variable as many times as you
want (all declarations should be identical), but you should only define it once.

As the OP did: the variable was defined because of the initializer (list) and then
it was defined again (using an identical initializer (list)).

Check the ANSI/ISO Standard for the distinction between declaration and definition.

Jos
Jul 27 '07 #3
ravenspoint
111 100+
Is that right? I confess I have always been vague about the difference between 'define' and 'declare'

Sorry abut that.

The thing to keep in mind is that when you write something like

int x;

the compiler allocates some memory where it keeps the value of x.

You cannot now tell it to store another variable with the same name somewhere else in memory.
Jul 27 '07 #4
weaknessforcats
9,208 Expert Mod 8TB
Is that right? I confess I have always been vague about the difference between 'define' and 'declare'
Define means to allocate memory. So these are definitions:
Expand|Select|Wrap|Line Numbers
  1. int data;
  2.  
  3. void fx()
  4. {
  5.     //etc...
  6. }
  7.  
Declare is to assert that something not defined does exist and is vaid to use. These are declarations:
Expand|Select|Wrap|Line Numbers
  1. extern int data;
  2.  
  3. void fx();
  4.  
  5. class MyClass
  6. {
  7.     //etc...
  8. };
  9.  
Jul 28 '07 #5

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

Similar topics

8
by: hb | last post by:
Hi, I need to declare a variable who's value can be preserve through the same ASP.Net page. I tried the following code, only the static variable s2 keeps its value=22 after lnk1_Click followed...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
2
by: HankD | last post by:
Hi, I am having a problem with instantiating two custom objects so they DO NOT point to the same memory location. What is happening is that changes I am making to my object1 are changing object2. I...
18
by: MajorSetback | last post by:
I am using the Redhat version of Linux and GNU C++. It is not clear to me whether this is a Linux issue or a C++ issue. I do not have this problem running the same program on Windows but...
11
by: dgk | last post by:
If I have a class with a public variable, isn't this the same as a private variable with a property? ie, isn't this: Public Class MyTest Public MyVar as String End Class the same as this: ...
12
by: raghu | last post by:
Hello I am working on a project where code optimization plays a vital role to get the required performance. I would like to know is there any possible to reinitialization an array of big size...
3
by: SRoubtsov | last post by:
Dear all, Do you know whether ANSI C (or some other dialects) support the following: * a variable name coincides with a type name, * a structure/union field name coincides with a type name in...
5
by: Twayne | last post by:
Hi, If ever a newbie wants to know how much he has to learn yet, he only has to look here<g>!! ANYway: PHP 5.2.5; XP Pro SP2+, local Apache Server My actual question is: How do I get a...
11
by: Jef Driesen | last post by:
I have the following problem in a C project (but that also needs to compile with a C++ compiler). I'm using a virtual function table, that looks like this in the header file: typedef struct...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.