The interface is simpler: one parameter in, the answer returned. You just check whether the pointer is null to verify success. The first form has some kind of other return value to check, which could be boolean, but I cannot tell, so I would have to look up the definitions of OK and NOK. And it is unclear from the interface whether I also need to check the pointer value, or indeed whether the pointer is NULL on failure. Looking into you implementation I can see that OK is returned if and only if the pointer is valid and the pointer is NULL on failure, but then I can write
so the return value is redundant -- it gives me no extra information.
However, if you want the function to indicate more than just a simple fail/succeed (e.g. different failure modes) then the first way is the only way to do it.
It mimics the standard malloc(3) function -- or it would do if the parameter was of type size_t rather than int -- and therefore has the benefit of familiarity, and makes it easier to port code written with malloc to use my_malloc.
void main()
{
int a={1,2,3,4,5,6,7,8,9,10};
int *p=a;
int *q=&a;
cout<<q-p+1<<endl;
}
The output is 10, how?
if we give cout<<q it will print the address, value won't print....
if we give cout<<p it will print the address, value won't print....
p has the base addr; q... (1 Reply)
Hi,
char *s="yamaha";
cout<<s<<endl;
int *p;
int i=10;
p=&i;
cout<<p<<endl;
1) For the 1st "cout" we will get "yamaha" as output. That is we are getting "content of the address" for cout<<s.
2) But for integer "cout<<p" we are getting the "address only".
Please clarify how we are... (2 Replies)
Hello all
im trying to build function that will return void function pointer
what is mean is ( not working )
the main function
void * myClass::getFunction(int type){
if(type==1)
return &myClass::Test1;
if(type==2)
return &myClass::Test2;
}
void myClass::Test1(){... (1 Reply)
I have a fundamental question on C pointer arithmetry..
Suppose i have a c string pointer already pointing to a valid location, Can I just do a
charptr = charptr +1;
to get to the next location, irregardless if my program is 32 or 64 bits?
or should i do it this way:
charptr =... (1 Reply)
Hi guys, I'm trying to understand pointers in C and made a simple example and I've problems with It.
Can someone help?
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int f1(char **str_);
int main(int argc, char **argv)
{
char *str = NULL;
f1(&str);
... (3 Replies)
I am struggling with the pointer to 2D-array (cf: 2D array of pointers). Can anybody help me elaborate how the pointer x moves in the memory to access the individual of y, especially the high lighted lines?
I have talked to one of the curators of the forum, but I am still not quite clear.
Here... (1 Reply)
I am passing a char* to the function "reverse" and when I execute it with gdb I get:
Program received signal SIGSEGV, Segmentation fault.
0x000000000040083b in reverse (s=0x400b2b "hello") at pointersExample.c:72
72 *q = *p;
Attached is the source code.
I do not understand why... (9 Replies)
Discussion started by: jose_spain
9 Replies
LEARN ABOUT HPUX
judysldel
JudySL_funcs(3X)JudySL_funcs(3X)NAME
JudySL functions - C library for creating and accessing a dynamic array, using a null-terminated string as an index (associative array)
SYNOPSIS
PPvoid_t JudySLIns( PPvoid_t PPJSLArray, const char * Index, PJError_t PJError);
int JudySLDel( PPvoid_t PPJSLArray, const char * Index, PJError_t PJError);
PPvoid_t JudySLGet( Pcvoid_t PJSLArray, const char * Index, PJError_t PJError);
Word_t JudySLFreeArray(PPvoid_t PPJSLArray, PJError_t PJError);
PPvoid_t JudySLFirst( Pcvoid_t PJSLArray, char * Index, PJError_t PJError);
PPvoid_t JudySLNext( Pcvoid_t PJSLArray, char * Index, PJError_t PJError);
PPvoid_t JudySLLast( Pcvoid_t PJSLArray, char * Index, PJError_t PJError);
PPvoid_t JudySLPrev( Pcvoid_t PJSLArray, char * Index, PJError_t PJError);
DESCRIPTION
A macro equivalent exists for each function call. Because the macro forms are faster and have a simpler error handling interface than the
equivalent functions, they are the preferred way of calling the JudySL functions. See JudySL(3X) for more information. The function call
definitions are included here for completeness.
One of the difficulties in using the JudySL function calls lies in determining whether to pass a pointer or the address of a pointer.
Since the functions that modify the JudySL array must also modify the pointer to the JudySL array, you must pass the address of the pointer
rather than the pointer itself. This often leads to hard-to-debug programmatic errors. In practice, the macros allow the compiler to
catch programming errors when pointers instead of addresses of pointers are passed.
The JudySL function calls have an additional parameter beyond those specified in the macro calls. This parameter is either a pointer to an
error structure, or NULL (in which case the detailed error information is not returned).
In the following descriptions, the functions are described in terms of how the macros use them (only in the case of #define JUDYER-
ROR_NOTEST 1). This is the suggested use of the macros after your program has been fully debugged. When the JUDYERROR_NOTEST macro is not
specified, an error structure is declared to store error information returned from the JudySL functions when an error occurs.
Notice the placement of the & in the different functions.
#define JSLI(PValue, PJSLArray, Index)
PValue = JudyLIns(&PJSLArray, Index, PJE0)
#define JSLD(Rc_int, PJSLArray, Index)
Rc_int = JudySLDel(&PJSLArray, Index, PJE0)
#define JSLG(PValue, PJSLArray, Index)
PValue = JudySLIns(PJSLArray, Index, PJE0)
#define JSLFA(Rc_word, PJSLArray)
Rc_word = JudySLFreeArray(&PJSLArray, PJE0)
#define JSLF(PValue, PJSLArray, Index)
PValue = JudySLFirst(PJSLArray, Index, PJE0)
#define JSLN(PValue, PJSLArray, Index)
PValue = JudySLNext(PJSLArray, Index, PJE0)
#define JSLL(PValue, PJSLArray, Index)
PValue = JudySLLast(PJSLArray, Index, PJE0)
#define JSLP(PValue, PJSLArray, Index)
PValue = JudySLPrev(PJSLArray, Index, PJE0)
Definitions for all the Judy functions, the types Pvoid_t, Pcvoid_t, PPvoid_t, Word_t , JError_t, and PJError_t, the constants NULL,
JU_ERRNO_*, JERR, PPJERR, and PJE0 are provided in the Judy.h header file (/usr/include/Judy.h). Note: Callers should define JudySL
arrays as type Pvoid_t, which can be passed by value to functions that take Pcvoid_t (constant Pvoid_t), and also by address to functions
that take PPvoid_t.
The return type from most JudySL functions is PPvoid_t so that the values stored in the array can be pointers to other objects, which is a
typical usage, or cast to a Word_t * when a pointer to a value is required instead of a pointer to a pointer.
AUTHOR
Judy was invented and implemented by Hewlett-Packard.
SEE ALSO Judy(3X), Judy1(3X), Judy1_funcs(3X), JudyL(3X), JudyL_funcs(3X), JudySL(3X),
malloc(3),
the Judy website, http://www.hp.com/go/judy/, for more information and Application Notes.
JudySL_funcs(3X)