Thread: problem with initializing a variable

  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,210
    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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    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?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  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, 01:50 AM
  2. problem with the const variable
    By ssharish in forum C Programming
    Replies: 2
    Last Post: 01-28-2005, 09: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, 01:25 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. Peculiar Problem with char variable in C Language
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 10-31-2001, 04:06 PM