lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

the purpose of ** besides 2-d array?

Thu Sep 03, 2015 8:21 pm

1)

Code: Select all

float **delta_clb_to_clb; 
delta_clb_to_clb[id_x][id_y];
case 1 is obvious,delt_clb_to_clb is declared with 2 level of pointers ** because it's for a 2-d array.


2)

Code: Select all

struct s_block {char *name; enum e_block_types type; int *nets; int x; int y;};  

block = (struct s_block *) my_malloc (num_blocks* sizeof(struct s_block)); 

static void alloc_and_assign_internal_structures( struct s_block **original_block,  int *original_num_nets)

why the function alloc_and_assign_internal_structures uses a 2 level pointer on s_block, it's not for 2 d array?


3)

Code: Select all

boolean **original_is_global 
what's the purpose of using 2 level of pointers on a boolean? Is that overkilled? it's obviously not for 2 d array.

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: the purpose of ** besides 2-d array?

Thu Sep 03, 2015 8:27 pm

Reading a basic C book would probably help.
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

Re: the purpose of ** besides 2-d array?

Thu Sep 03, 2015 9:10 pm

Joe Schmoe wrote:Reading a basic C book would probably help.
or general search around the google too for that matter. I guess eventually the answers would be there, someday.

User avatar
PeterO
Posts: 5880
Joined: Sun Jul 22, 2012 4:14 pm

Re: the purpose of ** besides 2-d array?

Thu Sep 03, 2015 9:14 pm

It's the same as it was the last time you asked the same question !

viewtopic.php?f=33&t=117850&p=801225#p801225

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

Re: the purpose of ** besides 2-d array?

Thu Sep 03, 2015 9:19 pm

PeterO wrote:It's the same as it was the last time you asked the same question !

viewtopic.php?f=33&t=117850&p=801225#p801225

PeterO

yeah, but the answer I got is related 2 -d array. what about Boolean ** ? you know?

User avatar
PeterO
Posts: 5880
Joined: Sun Jul 22, 2012 4:14 pm

Re: the purpose of ** besides 2-d array?

Thu Sep 03, 2015 9:43 pm

The previous answers you got made no reference to 2d arrays. I don't know where you got that idea from .

* is indirection (follow a pointer to the value)
** is double indirection (follow a pointer to a pointer, follow that pointer to the value) ( See the page on pointers to pointers that I posted last time you asked the same question).

The value type is irrelevant.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

danjperron
Posts: 3503
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: the purpose of ** besides 2-d array?

Thu Sep 03, 2015 11:47 pm

Multi Indirection is everywhere.

And it is just a way to specify how far you want to get the pointer of the pointer.

This code is valid

Code: Select all

#include <stdio.h>
int l0;
int *l1;
int **l2;
int ***l3;
int ****l4;
int *****l5;
int ******l6;
int *******l7;
int ********l8;
int *********l9;
int **********l10;
int ***********l11;
int ************l12;


int main(int agrc, char * argv[])
{
l0 =5;
l1 = &l0;
l2 = &l1;
l3 = &l2;
l4 = &l3;
l5 = &l4;
l6 = &l5;
l7 = &l6;
l8 = &l7;
l9 = &l8;
l10 = &l9;
l11 = &l10;
l12 = &l11;

   printf("************l12 = %d\n",************l12);
   return 0;
}

Code: Select all

pi@Pi2 ~ $ ./IndirectionLevel12
************l12 = 5
pi@Pi2 ~ $ 

User avatar
PeterO
Posts: 5880
Joined: Sun Jul 22, 2012 4:14 pm

Re: the purpose of ** besides 2-d array?

Fri Sep 04, 2015 6:36 am

danjperron wrote: This code is valid
In what universe is that going to be a helpful example to someone who doesn't seem to understand pointers and indirection ? :shock: :lol: :D

Remind me never to use any of your code :roll:

In 30 years of C programming I can't remember seeing or using anything more than double indirection.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
PeterO
Posts: 5880
Joined: Sun Jul 22, 2012 4:14 pm

Re: the purpose of ** besides 2-d array?

Fri Sep 04, 2015 6:49 am

lilzz wrote:yeah, but the answer I got is related 2 -d array.
Are you thinking about the definition of "main" ?

"char **argv" does NOT mean argv is a 2d array of characters. The alternative form "char *argv[]" is IMHO clearer. It reads as "argv is an array of pointers to characters, "

While this may look like a 2d array of characters, it is in fact a 1d array of pointers. The strings pointed to by each pointer in the array may NOT be the same length which they would have to be
in order to be considered as a 2d array (ie you can't say that argv is an "X by Y" 2d array because the value of "Y" can be different for each value of "X".

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

danjperron
Posts: 3503
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: the purpose of ** besides 2-d array?

Fri Sep 04, 2015 11:32 am

Remind me never to use any of your code :roll:
LOL! I will never use this code also!
It was just an example that it could be done and there is no limitation.

But I think you did or at least you figure out something about one of my post. Your display by removing one instruction after looking at my code ;-)

lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

Re: the purpose of ** besides 2-d array?

Fri Sep 04, 2015 5:39 pm

I don't see the advantage of using boolean ** versus boolean

is it because of itchy fingers??

User avatar
PeterO
Posts: 5880
Joined: Sun Jul 22, 2012 4:14 pm

Re: the purpose of ** besides 2-d array?

Fri Sep 04, 2015 5:45 pm

lilzz wrote:I don't see the advantage of using boolean ** versus boolean

is it because of itchy fingers??
To be honest if you don't see the advantage then you don't understand the difference.

It seems you really don't understand C and are trying a project that is much to advanced for you.

Go and find a good C book and read it because until you get a better understanding you are not going to get anywhere with your project.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Joe Schmoe
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm

Re: the purpose of ** besides 2-d array?

Fri Sep 04, 2015 8:42 pm

C is not a good programming language for people who need for there to be a one-to-one relationship between needs (problems) and solutions (tools).
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)

lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

Re: the purpose of ** besides 2-d array?

Fri Sep 04, 2015 10:08 pm

PeterO wrote:
lilzz wrote:I don't see the advantage of using boolean ** versus boolean

is it because of itchy fingers??
To be honest if you don't see the advantage then you don't understand the difference.

It seems you really don't understand C and are trying a project that is much to advanced for you.

Go and find a good C book and read it because until you get a better understanding you are not going to get anywhere with your project.

PeterO

Well, now be honest, how much memory space you can save with that?

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: the purpose of ** besides 2-d array?

Fri Sep 04, 2015 11:26 pm

lilzz wrote:
PeterO wrote:
lilzz wrote:I don't see the advantage of using boolean ** versus boolean

is it because of itchy fingers??
To be honest if you don't see the advantage then you don't understand the difference.

It seems you really don't understand C and are trying a project that is much to advanced for you.

Go and find a good C book and read it because until you get a better understanding you are not going to get anywhere with your project.

PeterO

Well, now be honest, how much memory space you can save with that?
How much memory space you can save with getting a good book that will explain the important concepts? If anything you'll learn a lot quicker. It's not easy to explain the concepts behind random snippets of code when you don't know the context and don't know how much the person asking already understands. A good book will be able to walk you through it and teach you everything you need to know first to be able to make sense of it.
She who travels light — forgot something.

User avatar
Paeryn
Posts: 2966
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: the purpose of ** besides 2-d array?

Sat Sep 05, 2015 12:30 pm

An attempt at explaining why you'd pass a pointer to a pointer using roughly what the OP had...

The alloc function is going to allocate memory for an s_block, this will give a "pointer to an s_block". The function needs to know where to store this pointer, so it needs the address of the variable "pointer to s_block" - which is where the "pointer to a pointer to an s_block" comes from.
She who travels light — forgot something.


Return to “C/C++”