Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Steve Litt
On Mon, 28 Mar 2016 13:57:08 -0300 Emiliano Marini wrote: > char *p; > p="01234"; /* skeezy, but makes the point */ > > Warning! Here "p" is pointing to nowhere, you don't know which memory > locations are writing to. Yeah, that's why I said "skeezy". But on some of compilers, you can actually

Re: [DNG] devuan installer main menu access

2016-03-28 Thread Gregory Nowak
On Mon, Mar 28, 2016 at 06:30:42PM -0400, Boruch Baum wrote: > 4.1] Was it a case of 'fat-fingerng'? I don't think so, but it's asking > a lot to attempt to re-create this because with slow bandwidth, each > install attempt takes a long time to get to this stage. Today's > connection was especially

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Emiliano Marini
Exactly, to modify a pointer you need a pointer to that pointer. Remember in C, function parameters are "read only" because they're always copies of the calling variable's values. This is wrong: function abcd(void *p) { p = malloc(sizeof(int)); // Memory leaking *p = 1; } main () { int *p

[DNG] devuan installer main menu access

2016-03-28 Thread Boruch Baum
Short version: From the screen that lets the user select specific system components to install, eg. XFCE, print server, SSH server, when I tabbed to the selection "go back" with the intention of getting the main menu, what happened instead was the installer began downloading "1173 packages". The on

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Edward Bartolo
Hi, Thanks for dedicating some of your time to answer me. I used: void change_value(void** ptr) Because I wanted to enable myself to allocate memory for the pointer inside the function, therefore I needed a pointer to a pointer of type void. Void allows such a function to handle different data t

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Rainer Weikusat
Roger Leigh writes: > On 28/03/2016 15:35, Steve Litt wrote: >> On Mon, 28 Mar 2016 06:03:13 -0400 >> Boruch Baum wrote: >> >>> Why on this list, of all the possible places in Creation? It's a great >>> and important topic, but have you found no other, more appropriate >>> forum? > >> Because we

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Roger Leigh
On 28/03/2016 15:35, Steve Litt wrote: On Mon, 28 Mar 2016 06:03:13 -0400 Boruch Baum wrote: Why on this list, of all the possible places in Creation? It's a great and important topic, but have you found no other, more appropriate forum? > Because we're developing software. I'd have to say

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Rainer Weikusat
k...@aspodata.se writes: > Rainer Weikusat: > ... >> One thing to note here: Every C pointer is really a pointer to an array >> of values, although the size of the array may just be one. > ... > > I thought it was the other way around, a pointer is just an address to > some (a single) memory locati

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Emiliano Marini
I was wrong because in this examples p was a pointer to int. Sorry, I was thinking on something like this: int *p; *p = 0; Cheers, Emiliano. On Mon, Mar 28, 2016 at 2:16 PM, Emiliano Marini wrote: > You're right. > > On Mon, Mar 28, 2016 at 2:04 PM, Rainer Weikusat < > rainerweiku...@virginmed

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Emiliano Marini
You're right. On Mon, Mar 28, 2016 at 2:04 PM, Rainer Weikusat < rainerweiku...@virginmedia.com> wrote: > Emiliano Marini writes: > > char *p; > > p="01234"; /* skeezy, but makes the point */ > > > > Warning! Here "p" is pointing to nowhere, you don't know which memory > > locations are writing

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Emiliano Marini
The main difference here is where you are storing the value "2000". In the first example, p is located in addresses belonging to "main" memory space (the stack presumably, beacuse "main" is the first function called upon start). You are passing the memory address of p (where p is located) to t

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Rainer Weikusat
Emiliano Marini writes: > char *p; > p="01234"; /* skeezy, but makes the point */ > > Warning! Here "p" is pointing to nowhere, you don't know which memory > locations are writing to. The 'memory location' (if any) reserved for the pointer p itself by the compiler, IOW, this is totally correct.

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Emiliano Marini
char *p; p="01234"; /* skeezy, but makes the point */ Warning! Here "p" is pointing to nowhere, you don't know which memory locations are writing to. char *p; *p=malloc...* p="01234"; /* skeezy, but makes the point */ On Mon, Mar 28, 2016 at 12:59 PM, Steve Litt wrote: > On Mon, 28 Mar 2016

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread karl
Steve Litt: ... > Years ago I gave up trying to logically explain the syntax of function > pointers, which are so essential for callbacks and pseudo-oop, and just > memorized the idiom. > > Edition 1 of K&R had an actual algorithm by which one could dissect any > lvalue (thing that can appear on t

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread aitor_czr
Hi Boruch, On 03/28/2016 02:00 PM, Boruch Baum wrote: Why on this list, of all the possible places in Creation? It's a great and important topic, but have you found no other, more appropriate forum? This is an appropiate list to argue about pointers. Have a look at the code of some projects

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Steve Litt
On Mon, 28 Mar 2016 12:28:03 +0200 (CEST) k...@aspodata.se wrote: > To exemplify the "as they are used" statement, take a function > pointer declaration: > > void (*log_func)(int priority, const char *format); > > here you cannot conveniently move the "*" to the "void" so it will > look like a

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Steve Litt
On Mon, 28 Mar 2016 14:51:19 +0200 (CEST) k...@aspodata.se wrote: > Rainer Weikusat: > ... > > One thing to note here: Every C pointer is really a pointer to an > > array of values, although the size of the array may just be one. > ... > > I thought it was the other way around, a pointer is jus

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Steve Litt
Because we're developing software. On Mon, 28 Mar 2016 06:03:13 -0400 Boruch Baum wrote: > Why on this list, of all the possible places in Creation? It's a great > and important topic, but have you found no other, more appropriate > forum? > > On 03/28/2016 02:50 AM, Edward Bartolo wrote: > > H

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread karl
Rainer Weikusat: > k...@aspodata.se writes: ... > > With pointers, you have to handle the special case of null pointers. > > I'm assuming you are omitting it here for brevity, but generally > > change_value() should be something like: > > > > void change_value(int* ptr) { > > if (!ptr) return; >

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread karl
Rainer Weikusat: > k...@aspodata.se writes: ... > > To exemplify the "as they are used" statement, take a function pointer > > declaration: > > > > void (*log_func)(int priority, const char *format); > > > > here you cannot conveniently move the "*" to the "void" so it will look > > like a "poin

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread karl
Rainer Weikusat: ... > One thing to note here: Every C pointer is really a pointer to an array > of values, although the size of the array may just be one. ... I thought it was the other way around, a pointer is just an address to some (a single) memory location which can be part of an array, I'd

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Rainer Weikusat
k...@aspodata.se writes: [...] > With pointers, you have to handle the special case of null pointers. > I'm assuming you are omitting it here for brevity, but generally > change_value() should be something like: > > void change_value(int* ptr) { > if (!ptr) return; > *ptr = 2000; > } It

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread karl
Edward Bartolo: ... > I am attaching two short C programs that I created and which I tested > to work although the mechanism by which they work is still somewhat > hazy to me. ... Some comments on test101.c #include void change_value(void* ptr) { *((int*) ptr) = 2000; } int main() {

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Rainer Weikusat
k...@aspodata.se writes: [...] > To exemplify the "as they are used" statement, take a function pointer > declaration: > > void (*log_func)(int priority, const char *format); > > here you cannot conveniently move the "*" to the "void" so it will look > like a "pointer" declaration; it declares

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Rainer Weikusat
Edward Bartolo writes: > As the title of the email indicates, I am doing some exercises to make > sense out of C pointer syntax. I have been using pointers for as long > as I have been programming without issues, apart from the usual > initial programmatic errors when new code is run for the first

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread karl
Edward Bartolo: ... > However, C pointer syntax is proving to be as unintuitive as it can > be. ... > I want to understand, as opposed to knowing by rote, the > mechanism why they work. ... /// I think one source of confusion re. c-pointers is that they are declared "as they are used", but you mi

Re: [DNG] Making sense of C pointer syntax.

2016-03-28 Thread Boruch Baum
Why on this list, of all the possible places in Creation? It's a great and important topic, but have you found no other, more appropriate forum? On 03/28/2016 02:50 AM, Edward Bartolo wrote: > Hi, > > As the title of the email indicates, I am doing some exercises to make > sense out of C pointer