I cant seem to solve this error i have in the malloc line of code. The error is "SIGABRT". Please teach me how to solve this problem. Thank you.
typedef struct caminho{
int nCient;
struct caminho *next;
}Caminho;
Caminho *temp1 = (Caminho*) malloc(sizeof(Caminho));
Update:
typedef struct caminho{
int nCient;
struct caminho *next;
}Caminho;
Caminho *temp1 = malloc(sizeof(Caminho));
the only other structure in the program and the only other malloc:
typedef struct Cientista{
int nCient;
int nSignal;
int profundidade;
int distancia;
struct caminho *next;
} cientista;
cientista* vectorCientistas;
scanf("%d %d", &maxCientista, &maxCaminhos);
vectorCientistas = malloc(sizeof(cientista*) * maxCientista);
PROBLEM FOUND!!
had:
vectorCientistas = malloc(sizeof(cientista*) * maxCientista);
solution:
vectorCientistas = malloc(sizeof(cientista) * maxCientista;
Was allocating memory for a pointer and i wanted a struct.
Related
in linux kernel driver is it possible to export a struct as a symbol? In other if there are 2 drivers i.e. Driver_A and Driver_B. And Driver_A has a struct test_a defined that is required to be exported so that Driver_B can directly reference struct test_a. Something like following
Driver_A has following structure defined
struct test_a {
int a,
long b,
int (*mem_write)(void *buf_priv, uint32_t size);
}
EXPORT_SYMBOL(test_a)
Driver_B
extern struct test_a test;
And method in Driver_B is able to access a,b and
Here's my code
#include <linux/list.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/printk.h>
#include <linux/slab.h>
typedef struct list_head list;
typedef struct student *ptr;
typedef struct student *studentDemo;
static LIST_HEAD(student_list);
struct student{
int studentNumber;
int courseCredit;
float grade;
studentDemo = kmalloc(sizeof(*studentDemp), GFP_KERNEL);
studentDemo -> studentNumber = 760120495;
studentDemo -> courseCredit = 3;
studentDemo -> grade = 3.0;
INIT_LIST_HEAD(&studentDemo->list);
}
I keep getting these errors
You have few problems:
typedef declaration is not creating a memory, therefore you can't assign something to a "typedef" string. typedef struct student * studentDemo - can be read "whenever the compiler will encoutner the string "studentDemo", replace with a pointer to a struct of type student". Obviously you can't assign anything to such a definition.
You can't assign memory to a pointer during the definition of the class/struct - this should be done during main where memory can be allocated from the stack.
You should first declare a member of type studentDemo (actually the pointer to the student struct) and then you can assign to it.
You should assign the memory during main().
Here is an example of C
#include <stdio.h>
#include <stdlib.h>
typedef struct student *studentDemo;
struct student
{
studentDemo myStruct;
};
void main()
{
struct student my_variable;
my_variable.myStruct = (studentDemo)malloc(1 * sizeof(studentDemo));
return;
}
Here:
typedef struct student *studentDemo;
you defined studentDemo as an alias-name for type (struct student *)
and here:
XXXX -> studentNumber
XXXX should be a pointer expression (posibly a variable of type struct student *), but not the type itself.
When I compile the following I get use of undeclared identifier 'rsdtHeader'
How can I do the following operation using typedef?
typedef struct
{
int length;
int x;
int y;
} SdtHeader_s;
typedef struct
{
SdtHeader_s rsdtHeader;
SdtHeader_s* rsdtEntry[(rsdtHeader.length - sizeof(rsdtHeader))/4];
} Rsdt_s;
what is the 'magic' value in tty_driver struct
struct tty_driver {
int magic; /* magic number for this structure */
struct kref kref; /* Reference management */
struct cdev cdev;
struct module *owner;
const char *driver_name;
....
....
/* tty driver magic number */
#define TTY_DRIVER_MAGIC 0x5402
From tty_driver.h listing here.
I know if we have task_struct, surly we can get the contained sched_entity because it's one field in the task struct. But can we get the pointer to the task_struct given the shed_entity? Following is the sched_entity structure:
struct sched_entity {
struct load_weight load; /* for load-balancing */
struct rb_node run_node;
struct list_head group_node;
unsigned int on_rq;
u64 exec_start;
u64 sum_exec_runtime;
u64 vruntime;
u64 prev_sum_exec_runtime;
u64 nr_migrations;
#ifdef CONFIG_SCHEDSTATS
struct sched_statistics statistics;
#endif
#ifdef CONFIG_FAIR_GROUP_SCHED
struct sched_entity *parent;
/* rq on which this entity is (to be) queued: */
struct cfs_rq *cfs_rq;
/* rq "owned" by this entity/group: */
struct cfs_rq *my_q;
#endif
};
It seems that there is no place where I can get the task_struct. My final goal is to get the sched_entity of the task group_leader containing the task with this shed_entity :>
The Linux kernel code provides a standard way to take a pointer to an element contained within a structure, and get back a pointer to the containing structure: the container_of macro, which is used extensively throughout the kernel.
In this case, if you have a struct sched_entity *foo, you can get the enclosing task_struct with:
struct task_struct *task = container_of(foo, struct task_struct, se);
(Obviously this is only safe if you know for sure that the original struct sched_entity * pointer is pointing to a struct sched_entity which is inside a struct task_struct, so be careful...)