#include <stdio.h>
#include <stdlib.h>
#include "state.h"

/******************************************************************************
                           functions
*******************************************************************************/


//** This is the function which should change "chip_count"
// Man soll einen Pointer auf einen Pointer auf die Struktur C<bergeben (wo sich chip_count befindet )
void
vtss_inst_create (vtss_inst_t * const inst)
{

  printf ("\r\n**vtss_inst_create()");
  vtss_state_t *vtss_state;	// temporary pointer  ( just points to a structure )

  // pass temporary pointer a new memory space:
  vtss_state = malloc (sizeof (*vtss_state));	// is this correct? anyway it also doesnt work without this malloc style
  printf ("\r\n\t malloc=: %d", vtss_state);
  //Test:Change values of the structure:

  vtss_state->chip_count = 12121;
  // ** Giving back the new adress from malloc:
  // Test:(from vtss_state or vtss_state2)
  (*inst) = vtss_state;		//passing adress1

}

/******************************************************************************
                           main
*******************************************************************************/


int
main ()
{
  // **The main structure:
  vtss_state_t state_test;
  // **pointer to type of vtss_state_t
  vtss_inst_t inst;
  // **pass the adress of the structure!:
  inst = &state_test;
  // Test value: 
  inst->chip_count = 888;
  // call the create function:
  printf ("\r\n * Before create(): Adress  inst:%d", inst);
  printf ("\r\n * chip_count: %d", inst->chip_count);
  vtss_inst_create (&inst);
  printf ("\r\n\n * After create(): Adress of inst:%d", inst);
  printf ("\r\n\n\n******* chip_count 12121??: %d\n\n\n", inst->chip_count);

  return 0;
}

#include <stdint.h>

/******************************************************************************
                           Structures
*******************************************************************************/
//test structure:
typedef struct tests
{
  int x;
} tests_t;


typedef uint32_t u32;

// This is the structure with  chip_count :
typedef struct vtss_state_s
{
  int a;
  int cookie;
  tests_t u;
  int port_count; 
  u32 chip_count // doesnt change in my real program :(

} vtss_state_t;

// typedef this structure so vtss_inst_t points to it...(?)
typedef struct vtss_state_s *vtss_inst_t;


