problem with initializing a variable

This is a discussion on problem with initializing a variable within the C Programming forums, part of the General Programming Boards category; Hello, I'm coding a plugin for Wireshark. I want to use a global variable for doing some stuff which refers ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    8

    problem with initializing a variable

    Hello,

    I'm coding a plugin for Wireshark. I want to use a global variable for doing some stuff which refers to all packets.

    Code:
    static guint32 i = 0
    For testing I print i each time i get a packet and increment it after printing. That works fine, but my problem is, that at the first time I print i, it has the value 198 instead of 0.

    I also tried other data types like gint, int.

    Can somebody help me how to inialize i in a way, that is really zero.

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    You are describing a problem and jumping to a conclusion.

    The problem is that your variable is changing value against your expectations, and the conclusion is that the assignment is not working. This conclusion is probably quite faulty and the result as to why you are unable to fix it.

    The root of the problem most likely lies elsewhere. Either you are changing the number or some other function is changing it without your knowledge. Without seeing code it's pretty much impossible for us to tell you what the problem is, and as such, how to remedy it.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    or maybe some memory overrun
    have you tried to print the i in the DLLMain or something - ie before any real processing is done - just on the attach event of the plug-in?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Jun 2007
    Posts
    7
    Im not the king of C, but in java (Eclipse environnement), there is a way to run in debug and break on value change. If that is possible in your environnement, it would allow you to identify where you i is modified. Not sure it will work if the problem is due to a memory leak though

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem getting the input from a temp variable into the Array
    By hello_moto in forum C++ Programming
    Replies: 3
    Last Post: 03-16-2006, 12:50 AM
  2. problem with the const variable
    By ssharish in forum C Programming
    Replies: 2
    Last Post: 01-28-2005, 08:53 AM
  3. Problem with a char variable set as a letter
    By 7smurfs in forum C++ Programming
    Replies: 6
    Last Post: 12-10-2004, 12:25 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 01:45 PM
  5. Peculiar Problem with char variable in C Language
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 10-31-2001, 03:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21