Thread: Need help in analyzing pointer and macro implementation.

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    147

    Need help in analyzing pointer and macro implementation.

    Hello Friends,

    I have follwoing code.

    Code:
     
     28 struct pkt_pool_t;
     29
     30 typedef int (*PKT_POOL_GET_TRAFFIC) (struct pkt_pool_t *pool, pkt_t **pkt, pkt_message_t **msg);
     33 typedef int (*PKT_POOL_FREE) (struct pkt_pool_t *pool, pkt_t *pkt);
     34 typedef uint32_t (*PKT_POOL_GET_FAIL_COUNT) (struct pkt_pool_t *pool);
     35 
     36 struct pkt_pool_t {
     37     PKT_POOL_GET_TRAFFIC temp_traffic;
     40     PKT_POOL_FREE free;
      42 };
     43 
     44 static inline int __attribute__ ((always_inline))
     45 pkt_pool_get_traffic(struct pkt_pool_t *pool, pkt_t **pkt, pkt_message_t **msg)
     46 {
     47     assert(pool && pool->temp_traffic);
     48 
     49     return (*pool->temp_traffic) (pool, pkt, msg);
     50 }
     51

    I am trying to find out , which function will be fired with "temp_traffic" here.

    I understand below points.

    1.pool is struct variable and temp_traffic will be function pointer which takes three varaiables.
    2.temp_traffic is of type "PKT_POOL_GET_TRAFFIC".

    from here i could not able to crack this.

    any help would be highly appreciated.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    There is nothing to crack: pkt_pool_get_traffic is never called, hence no 'function will be fired with "temp_traffic" here'.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    You need to find all the places where the function pointer is assigned.
    var->temp_traffic = aFunction;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function pointer to macro, possible?
    By edwood in forum C Programming
    Replies: 6
    Last Post: 05-25-2012, 03:38 PM
  2. Subtracting a macro from a pointer
    By limp in forum C Programming
    Replies: 2
    Last Post: 05-24-2011, 06:38 AM
  3. need help with analyzing some code
    By happyclown in forum C Programming
    Replies: 7
    Last Post: 01-30-2009, 08:00 AM
  4. Packet Analyzing
    By Halloko in forum Windows Programming
    Replies: 0
    Last Post: 02-27-2005, 01:10 PM
  5. Analyzing Code
    By smitsky in forum C++ Programming
    Replies: 13
    Last Post: 01-12-2005, 05:33 PM