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

Scope error

2
void func1(void)
{

strans obj;\\\\struct
unsigned int i,ix;
ix=1;

if (a>0)\\\\\\\\\\\\\a is global int
ix=a;

for (i=ix;i<5;i++)
{
func2(i,obj);
\\\\\\\\\\\\\\\\\\\\\\i value here i =1 ok
func3(obj);
\\\\\\\\\\\\\\\\\\\\\\ func3 ok
\\\\\\\\\\\\\but after this func3 call i value===0\\\\\error
\\not making any change to or passing address of i in func3 but still getting \\reset
\\if i use static for i variable it works correctly
\\but scope of i even though local is through out function1 is it not?
\\please tell me why this problem occurs..


}

}

could it be a stack problem were i is lost when func3 is called ,,isnt static used the other way around to retain i value when flow exits out of func1..thankyou for all posts
Sep 27 '09 #1
4 1561
Banfa
9,065 Expert Mod 8TB
You probably have a problem in func3, some sort of out of bounds write to a local array variable in func3 could corrupt the local data in func1.
Sep 27 '09 #2
avi05
2
thankyou bafta i am using a gnu cross compiler when i got this error ,but when the same code is ported to borland bc5 it works correctly...could it be compiler optimisation in bc5 that is avoiding this out of bounds write into array...
Sep 28 '09 #3
newb16
687 512MB
It may be anything - endianness, word/dword alignment, difference in size of int/long types. Try to pad i,ix declaration with some local arrays filled with some like 0xcc and see then what happens to them and how much of them is zeroed.
Sep 28 '09 #4
Banfa
9,065 Expert Mod 8TB
@avi05
If you are writing outside of an array bounds then you have invoked undefined behaviour.

Anything can happen with undefined behaviour including the program appearing to work and it is likely that different things would happen on different platforms so just because your code appears to work in Borland BC5 doesn't mean that there is no error in the code. It just means BC5 is reacting to undfined behaviour in a different way to the gnu cross compiler.

You need to check the code of func3 and see if you can see the error.
Sep 28 '09 #5

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

Similar topics

5
by: William | last post by:
In Peer.h, I have: class Peer { // ... }; In Overseer.h, I have: #include "Peer.h" #include <vector>
9
by: Neelesh | last post by:
I was reading TC++PL (Chapter 11, section 11.5.1 "finding friends") where it is mentioned that What I observe is a bit different - it is fine that there is an error for Xform, but the reason...
8
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an...
3
by: marco_segurini | last post by:
Hi, I am using VS 2005. If I compile the following code only line 6 returns me an error while line 9 returns a warning. If I comment the line 6 and debug the program the assignments of lines...
1
by: timbobd | last post by:
I have encountered a situation that I don't understand. When I call a sub of Friend scope (in an object with Friend scope), I am getting an error "Public member 'subname' not found in type...
3
by: namewitheldbyrequest | last post by:
"The XML element 'EnableTheming' from namespace 'http://tempuri.org/' is already present in the current scope" I created a Web Service: I imported System.Data.SqlClient so I could access SQL...
15
by: Paddy | last post by:
Hi, I am trying to work out why I get UnboundLocalError when accessing an int from a function where the int is at the global scope, without explicitly declaring it as global but not when accessing...
26
by: Patient Guy | last post by:
The code below shows the familiar way of restricting a function to be a method of a constructed object: function aConstructor(arg) { if (typeof(arg) == "undefined") return (null);...
3
by: John Rivers | last post by:
try catch blocks create a new scope i don't think that they should for example, to add error handling to this statement: int x = 1; you have to rewrite it as a seperate declaration and...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.