Programming :: C - Malloc For A Void Pointer?
Mar 20, 2010So far I have this:
Code:
int mm_init (mm_t *MM, int hm, int sz) {
int i;
[code]...
So far I have this:
Code:
int mm_init (mm_t *MM, int hm, int sz) {
int i;
[code]...
I have been trying to get a void pointer cast to work and I seem to have some problems. My code compiles, but when I execute it gives back garbage data. I'm not sure what I'm doing wrong.
Code:
int main()
{
[code]....
I have a problem with correctly using a void pointer. I am writing a system that can open plugins and run them, and so far everything is going fine: I have a struct with some variables in, some function pointers, and I've written a small library to handle these correctly to communicate with the plugin. My challenge is that I need to put a pointer (let's call it "context") into this struct. The type is not important to the main body of code, and it is not ever used except by the plugin. The plugin will malloc some space for itself, and this *context will then point to whatever malloc returned. context is the address to a struct that I typedeffed to "ctxt".
Here is the first struct I mentioned:
Code:
typedef struct slave {
int val1;
int val2;
int (*entry)(struct slave*, int a, int b);
void *context;
} target;
Here are some snippets from the plugin:
Code:
typedef struct context {
int a;
int b;
} ctxt;
(*target).context = malloc(sizeof(struct ctxt));
So that (*target).*(ctxt)*context.a should refer to the int a in struct context.
But the error that the compiler gives me is a syntax one:
"expected identifier before '*' token"
Is my logic correct? Is my C correct?
I have written a small character driver, in the cleanup module at the line
int a=unregister_chrdev(Major,DEVICE_NAME);
I am getting the following error
error: void value not ignored as it ought to be
If the value return by unregister_chrdev() function is not stored in any variable it is working fine...
I was going through a file known as linux-2.6.34/kernel/timer.c and found following code.
static inline void
timer_set_base(struct timer_list *timer, struct tvec_base *new_base)
{
timer->base = (struct tvec_base *)((unsigned long)(new_base) |
tbase_get_deferrable(timer->base));
}
I want to understand what is it doing. What is the meaning of static inline in above? I searched and came across
[Code]...
I have been googling trying to fix this ... basicly I have a (int **) variable, and when I try to pass a (int) value to a specific position, I have seg.fault.Resuming what I have is:
int ** p;
p[0][0] = 1; //segmentation fault
So, DnD is cool - and in Java, it works. Just set the component where the drag starts to allow that:
Quote: tblMain.setDragEnabled(true);
and - yes - the rest pretty much runs itself. I have a JTextField that happily takes the drop from the JTable (be it the whole row - I'm not there yet, still working on that)...but does not raise any events. I'd like the JTextField to raise an event:
- cleaning up the received data, now it gets the raw stuff, and I need an ID from that string
- starting up another void() with the received ID
I read the tutorials but - for blisters - cannot see the "light", please shed some (light, that is)
How do you malloc a struct in C? I have a structure of the form:
Code:
typedef struct child_req_to_parent
{
[code]...
Code:
#include <stdio.h>
#include <stdlib.h>
[code]...
So the place where I'm having a problem is here:
Code:
typedef struct {
void **Mem_Chunk;
[code]...
I have encountered this scenario wherein malloc does not return.
Code:
char * tmp;
rs = 100 to 40000 bytes
[code]...
I am developing a code where I need to store the planes of an object in a tree & also i need to store it in a list for further processing ... when I try to allocate using malloc the memory allocation when i checked this in internet , I came to know that it may because the memory that I am trying to allocate may be more than the size_t variable.
View 9 Replies View RelatedIs there a way to hook calls to new/malloc, delete/free in C++? I tried the following methods: LD_PRELOAD -> fails for malloc, because dlsym seems to depend on malloc -Wl,--wrap,malloc -> doesn't work for 'new' gcc hooks -> doesn't work always, e.g. for uclibc there are no hooks Are there any other methods I could try?
View 2 Replies View RelatedI am new to C and linux. My code below does arbitary writes but I cant figure out where or how it does it.
I am calling the insertNode() function with seq = 'MISSISSPPI$' and alphabets = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ$'
Code:
Weird behaviour I should mention is that when I check for NULL pointer in node->child[index], the unassigned values are not null anymore, they point to arbitary memory.
Is it possible to check if a pointer is deleted in C++ (using GDB)? For example:
Code:
a = new Thing();
b = a;
delete a;
// If all I have is the variable "b", how can I tell if it was deleted?
I'm trying to write a simple program that lists a menu and then asks you for your decision, and you can answer with a number or the name. However, I don't know how to add the second options (name).
View 14 Replies View Related#!/bin/bash
sed -n 8p file.txt
returns the 8th line to the StdOut.
If I assign the value to the variable line = $(sed -n 8p file.txt)
and now print it out with echo
echo $line
the line would be printed.
But what if the file has only 4 lines. What value would be assigned to the variable line?
I want to know that because I want to only print it if the value is "something", that is not null.
In Java for example I would do it like this...
String line = "";
line = reader.readLine(); // or anything else..
if(line!=null){
System.out.println(line);
}
How would I check if the value is not "null"(I don't know if bash knows null)
Code:
#include <stdio.h>
int main ()
[code]...
Whats the practical diffrens between these declarations in c?
char *a_str = "hello";
char a_str[] = "hello";
i was trying to access the address of the character pointer it gives me the values stored in the variable.
Code: #include<iostream>
using namespace std;
int main()
{
char *i;
[Code]....
why is my code not giving the address of the variable i when it is a character pointer.
I'm getting some information about C language and this session of a C book (follow the above link) is using a bad example for me. When I'm trying this example of function returning a pointer, my compiler is stating a warning that I return a pointer to a local variable. I realized that it is error prone after all this variable may be override before the function has done his execution. And the author is fooling me saying that this example is "perfectly safe". I'm wrong? There is something that I don't got yet? Sorry but this site is preventing me to post the link of book cause I'm a newbie, so a need the hack it. Just strip out the question signs:
{LINK}
?w?w?w
?cs.cf.ac.uk?
[code]....
I want to assign an address location to a pointer and wanted to display the value at that memory location.I wrote a small program for this and it is like this : (i am using gcc 4.4 compiler)
# include "stdio.h"
int main()
{
unsigned int *a;
a=(unsigned int *)0x3f8;
printf("%u",*a);
return 0;
}
But it is giving Segmentation fault
i am trying to find the size of an array, not by using the array as a parameter to "sizeof", but by using a pointer -pointing to the array- as a parameter. How do i do this?I use a 32-bit PC.Here's:
Code:
#include <string>
#include <iostream>
[code]...
This is one of the strangest problems I've run into while programming. Maybe there's just something wrong with my version of gcc or something.
The main problem comes at this point in the code:
Code:
po = makePoFromScorbotXYZPR(X, Y, Z, P, R);
h = makeHB2GFromPo(po);
printf("%le", *h[1][0]); //##################################### Here it has the right value
printf("%s", "
[Code].....
I have got following code from a book:
Code:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <stdlib.h>
#define PORTNUMBER 12345
[Code]...
From "man gcc"
-Wno-int-to-pointer-cast (C and Objective-C only)
Suppress warnings from casts to pointer type of an integer of a different size.
[code]...
How could i create a script that will move the mouse pointer around the screen.i'm thinking i need the Xlib modules (which i have installed) but don't know how to implement them
View 5 Replies View RelatedHow do I get the page pointer from a physical address?
View 1 Replies View RelatedI have what should be a relatively simple program (fadec.c) that maps a struct from an included header file (fadec.h) to a shared memory region, but Im struggling accessing members in the struct from the pointer returned by shmat. Ultimately, I want to access members in the shared memory structure with a globally declared version of the struct, shm__. Not only do I not know how to accomplish that, but I cant even seem to access members of the shared struct directly from the pointer itself (compiler complains about dereferencing pointer to incomplete type). Im at a loss and could use another set of eyes if you guys dont mind taking a gander:
Compile Errors:
tony-pc:/cygdrive/p/test> cc -o fadec fadec.c
fadec.c: In function 'main':
fadec.c:30: error: dereferencing pointer to incomplete type
fadec.c:31: error: dereferencing pointer to incomplete type
[Code]...
I'm venturing into the world of OpenGL, but in the process of writing my graphics library I ran into a problem... My code is:
Code:
#include <stdio.h>
#include <stdlib.h>
[code]...