M
Mark
Hello,
consider the following code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#define NAME_LEN 16
#define MAX_INSTANCES 64
struct inst_info
{
uint32_t state;
uint32_t port_mem;
};
struct vid_entry
{
struct vid_entry *prev;
struct vid_entry *next;
uint16_t vid;
uint32_t vid_state;
};
struct hsl
{
char name[NAME_LEN + 1];
uint32_t ageing_time;
unsigned char flags;
int learning;
/* Platform specific information. */
void *system_info;
struct vid_entry *inst_table[MAX_INSTANCES];
struct inst_info inst_info_table[MAX_INSTANCES];
};
int main(void)
{
struct hsl *br;
br = malloc (sizeof (struct hsl));
if ( !br)
{
puts("malloc() failed");
return -1;
}
memset ((void *)&br->inst_info_table, 0, sizeof (struct inst_info) *
MAX_INSTANCES);
memset ((void *)&br->inst_table, 0, sizeof (struct vid_entry *) *
MAX_INSTANCES);
free (br);
return 0;
}
As I understand it, 'inst_table' is the array of pointers to 'struct
vid_entry' and on my system pointer is 32-bit wide, so I want to make sure
that the code is correctly initializing memory allocated for 'struct hsl'
object.
Also, is (void *) necessary or more a pedantic element?
Thanks !
Mark
consider the following code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#define NAME_LEN 16
#define MAX_INSTANCES 64
struct inst_info
{
uint32_t state;
uint32_t port_mem;
};
struct vid_entry
{
struct vid_entry *prev;
struct vid_entry *next;
uint16_t vid;
uint32_t vid_state;
};
struct hsl
{
char name[NAME_LEN + 1];
uint32_t ageing_time;
unsigned char flags;
int learning;
/* Platform specific information. */
void *system_info;
struct vid_entry *inst_table[MAX_INSTANCES];
struct inst_info inst_info_table[MAX_INSTANCES];
};
int main(void)
{
struct hsl *br;
br = malloc (sizeof (struct hsl));
if ( !br)
{
puts("malloc() failed");
return -1;
}
memset ((void *)&br->inst_info_table, 0, sizeof (struct inst_info) *
MAX_INSTANCES);
memset ((void *)&br->inst_table, 0, sizeof (struct vid_entry *) *
MAX_INSTANCES);
free (br);
return 0;
}
As I understand it, 'inst_table' is the array of pointers to 'struct
vid_entry' and on my system pointer is 32-bit wide, so I want to make sure
that the code is correctly initializing memory allocated for 'struct hsl'
object.
Also, is (void *) necessary or more a pedantic element?
Thanks !
Mark