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

Initialization to zero suddenly changes value

2
Hi,

I'm running a simulation over time and I'm having trouble with arrays in my C program. An array element that has been initialized to zero suddenly changes value to 13 after a few time points, and surprisingly, this only happens in some runs. If I print out values from different parts of the program, I can clearly see the value changing.

I am not using dynamic memory allocation, so I'm not sure why I see this strange behavior. Has anybody seen such behavior before and do you have any idea what could be causing the problem?

I am stuck at this point and I'm not sure how to proceed. Any suggestions/advice will be greatly appreciated.
Dec 11 '08 #1
5 1651
JosAH
11,448 Expert 8TB
Without seeing any code I guess/suspect that some char[] is overwritten and causes a worm (too many chars are written to that array); but I could very well be wrong though.

kind regards,

Jos
Dec 11 '08 #2
simmol
2
The code is very long..I could e-mail it to you.

Thanks!
Dec 11 '08 #3
r035198x
13,262 8TB
You could try posting the parts of the code that you suspect.
Dec 12 '08 #4
JosAH
11,448 Expert 8TB
Look at the variables that are defined just before that mysteriously changing variable in the same scope; especially suspect the char[] variables; check the code that manipulates those variables. The error is most likely somewhere in that code.

kind regards,

Jos
Dec 12 '08 #5
weaknessforcats
9,208 Expert Mod 8TB
Almost certainly you have a pointer error and I suspect your array handling code is scatttered throughout the program. The first thing I would do is write a series of functions to manage that array and call those functions as needed elsewhere in the program.
Dec 12 '08 #6

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

Similar topics

5
by: Michael W. Hicks | last post by:
Hello, Consider the following code snippet: int x = { 1, 2 }; What is the value of x? My assumption was that this value is undefined and dependent upon the compiler implementation, as...
10
by: JKop | last post by:
What's the difference between them? Take the following: #include <iostream> struct Blah { int k;
10
by: utab | last post by:
Dear all, Can somebody direct me to some resources on the subject or explain the details in brief? I checked the FAQ but could not find or maybe missed. Regards,
5
by: Jesper Schmidt | last post by:
When does CLR performs initialization of static variables in a class library? (1) when the class library is loaded (2) when a static variable is first referenced (3) when... It seems that...
3
by: Alex Howlett | last post by:
Stroustrup page 663 says this: valarray<floatv1 (1000); // 1000 elements with value float()==0.0F But when I run this program: -------------------------------------- #include <valarray>...
23
by: Jess | last post by:
Hello, I understand the default-initialization happens if we don't initialize an object explicitly. I think for an object of a class type, the value is determined by the constructor, and for...
4
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
17
by: copx | last post by:
I don't know what to think of the following.. (from the dietlibc FAQ) Q: I see lots of uninitialized variables, like "static int foo;". What gives? A: "static" global variables are initialized...
4
by: subramanian100in | last post by:
Suppose I have #include <cstdlib> #include <iostream> using namespace std; class Test { public:
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.