If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
(2)the other is to return a pointer, like:
Could anyone tell the difference(advantages and disadvantages )about those two methods ?
Thanks in advance !
Last edited by Franklin52; 01-06-2009 at 07:17 AM..
Reason: adding code tags
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 MOJAVE
dispatch_api
dispatch_api(3) BSD Library Functions Manual dispatch_api(3)NAME
dispatch_api -- Designing API using dispatch
DESCRIPTION
The following is a brief summary of some of the common design patterns to consider when designing and implementing API in terms of dispatch
queues and blocks.
A general recommendation is to allow both a callback block and target dispatch queue to be specified. This gives the application the greatest
flexibility in handling asynchronous events.
It's also recommended that interfaces take only a single block as the last parameter. This is both for consistency across projects, as well
as the visual aesthetics of multiline blocks that are declared inline. The dispatch queue to which the block will be submitted should immedi-
ately precede the block argument (second-to-last argument). For example:
read_async(file, callback_queue, ^{
printf("received callback.
");
});
When function pointer alternatives to interfaces that take blocks are provided, the argument order of the function signature should be iden-
tical to the block variant; with the exception that the block argument is replaced with a context pointer, and a new last parameter is added,
which is the function to call.
The function based callback should pass the context pointer as the first argument, and the subsequent arguments should be identical to the
block based variant (albeit offset by one in order).
It is also important to use consistent naming. The dispatch API, for example, uses the suffix "_f" for function based variants.
SEE ALSO dispatch(3), dispatch_async(3), dispatch_queue_create(3)Darwin May 1, 2009 Darwin