Thread: Dealing with pointers and values when calling functions

  1. #1
    Registered User
    Join Date
    May 2019

    Dealing with pointers and values when calling functions


    I have just started getting my head around C programming. At some point of my program, I have:

        max_basket = 0;
        for (i = 0; i< num_threads; i++) {
                LONG opt_basket_abs_cost = opt_basket[i]->abs_cost;
                LONG max_basket_abs_cost = max_basket->abs_cost;
                int  opt_basket_a_id = opt_basket[i]->a->id;
                int  max_basket_a_id = max_basket->a->id;
        if ((!max_basket && opt_basket[i]) || (opt_basket[i] && cost_compare(opt_basket_abs_cost, max_basket_abs_cost, opt_basket_a_id, max_basket_a_id) < 0)) {
            max_basket = opt_basket[i];
    I have to pass values rather than pointers to the function "cost_compare". And here is definitions:
                  BASKET*           max_basket;
    static     BASKET        *basket;
    static     BASKET        **opt_basket;
    typedef struct basket
        arc_t *a;
        cost_t cost;
        cost_t abs_cost;
        LONG number;
    } BASKET;
    struct arc
      int id;
      cost_t cost;
      node_p tail, head;
      short ident;
      arc_p nextout, nextin;
      flow_t flow;
      cost_t org_cost;
    } ;
    But when I compile (eclipse IDE), I get

    Program received signal SIGSEGV, Segmentation fault.
    0x0000555555559e85 in master (net=0x55555575d0a0 <net>, num_threads=1) at ../src/psimplex.c:195
    195                       LONG max_basket_abs_cost = max_basket->abs_cost;
    Program terminated with signal SIGSEGV, Segmentation fault.
    The program no longer exists.
    I appreciate if someone can give me a hint how to fix this without altering function's parameeters.


  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Melbourne Australia
    What does "max_basket" point to? I think that you'll find that you have given it a value of 0.
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-03-2013, 09:26 PM
  2. Replies: 12
    Last Post: 04-12-2009, 05:49 PM
  3. Arrays, and Functions dealing with them
    By Argentum in forum C++ Programming
    Replies: 6
    Last Post: 12-05-2005, 07:25 PM
  4. Replies: 4
    Last Post: 03-11-2005, 05:45 PM
  5. Dealing with functions and reading char
    By hermit in forum C++ Programming
    Replies: 11
    Last Post: 06-12-2002, 06:07 AM

Tags for this Thread