Computing desk | ||
---|---|---|
< October 20 | << Sep | October | Nov >> | October 22 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
From one of these...
...before disposal. Thanks, hydnjo ( talk) 00:25, 21 October 2010 (UTC)
I'm really kind of confused with pointers in C. Let's say you malloc a blob of memory:
void * blob = malloc(sizeof(char *) + sizeof(int));
and you use the blob to hold two things like this: | a char * | integer value |
so blob would point to the memory adress of the beginning of the blob of malloc'd memory.
If you made a pointer to point to it:
void * pointToBob = bob;
Could you use bob and pointToBob interchangeably?
Or what if you had
void ** pointToBob = bob;
How could you used that?
I'm confused how you could possibly use a pointer to a pointer to change a value in the originally malloc'd blob. I'd appreciate any help with this problem and any sort of general explanations on the questions of pointers. I feel like I don't understand much more than "a pointer holds an adress to a place in memory". Thank you very much :) —Preceding unsigned comment added by Legolas52 ( talk • contribs) 00:58, 21 October 2010 (UTC)
void * pointToBlob = blob;
makes pointToBlob have the same type and value as blob. However, void ** pointToBlob = blob;
will give you a compile warning, because a pointer to a pointer is not the same type as a pointer. But a more basic problem is that your malloc line is a thing that ought not to be done. In some systems, the "int" type must be aligned in a specific way in memory space, so it may not be possible to store an int at the place you think you are going to store it. This is simply bad code. Even if it works, referring to things in memory that has been allocated in this way is so ugly that I'm not even going to try to write it. If you want to store multiple different things in a single block of memory, create a struct to hold them.
Looie496 (
talk)
01:23, 21 October 2010 (UTC)void ** pointToBlob = blob;
is legal C and won't produce a warning, because C allows void *
to be implicitly converted to any other pointer type (though C++ doesn't). There's no deep logic to this; it's just a special exception intended to make malloc
easier to use. The result of this definition will be that pointToBlob
will point to the same memory block as blob
does, except that it will "think it's pointing to" a void *
. You could then store a void *
into the memory block through that pointer, even though you allocated space for a char *
, because those pointer types happen to be guaranteed to have the same size. But that's probably not what you intended. If you wanted a pointer to the blob
variable itself (which is a different thing from the memory you allocated), then you should have written pointToBlob = &blob
instead of pointToBlob = blob
.&foo
then you get a value that points to foo
, if you say *p
in an expression then you get the value of whatever p
points to, and if you say *p = (whatever);
then you change the value of whatever p
points to. For example, if you wrote void ** pointToBlob = &blob;
, then *pointToBlob = malloc(100);
would be the same as blob = malloc(100);
(they both write the result to the blob
variable). But if you wrote void * pointToBlob = blob;
and then pointToBlob = malloc(100);
, you would be assigning to the variable pointToBlob
, which is a different variable from blob
, so blob
would remain unchanged. Although those rules are simple, they're hard to think about. The reason seems to be that human beings are not good at separating the name of something from the thing itself. For example, what does pointToBlob
mean? Do you intend it to point to the variable named "blob", or are you thinking of the memory you allocated as the "blob" that it points to? This kind of ambiguity is what makes pointers difficult. The good news is that it gets easier with practice. --
BenRG (
talk)
02:16, 21 October 2010 (UTC)char *
and an int
like that. You can, however, do it like this:struct mystruct { char *p; int i; }; struct mystruct *blob = malloc(sizeof(struct mystruct));
blob->p
and blob->i
to refer to the char *
and int
values, assuming the malloc()
succeeded. You can easily check this, because if malloc()
fails, the resulting value will be a null pointer.
JIP |
Talk
12:09, 21 October 2010 (UTC)int n,i;
float *a;
printf("How many questions are on the math test? ");
scanf("%d",&n); /* give scanf() a pointer to n so it can assign to n through it */
a=malloc(n*sizeof*a); /* enough space for n floats; *a is a float, so sizeof*a==sizeof(float) */
printf("What are the answers? ");
for(i=0;i<n;++i) scanf("%g",a+i); /* a[i]==*(a+i), so a+i==&a[i] and we store into each in turn */
int nt,*nq,i,j;
float **a;
printf("How many math tests? ");
scanf("%d",&nt);
a=malloc(nt*sizeof*a); /* enough space for nt float _pointers_ */
nq=malloc(nt*sizeof*nq); /* enough space for nt ints */
for(i=0;i<nt;++i) {
printf("How many questions are on test #%d? ",i);
scanf("%d",nq+i);
ai=malloc(nqi*sizeof*ai]); /* enough space for nq[i] floats */
printf("What are the answers? ");
for(j=0;j<nqi];++j) scanf("%g",ai+j);
}
struct test {int n; float *ans;};
int nt,i,j;
struct test *a;
printf("How many math tests? ");
scanf("%d",&nt);
a=malloc(nt*sizeof*a); /* enough space for nt test structures */
for(i=0;i<nt;++i) {
printf("How many questions are on test #%d? ",i);
scanf("%d",&ai].n);
ai].ans=malloc(ai].n*sizeof*ai].ans); /* enough space for a[i].n floats */
printf("What are the answers? ");
for(j=0;j<ai].n;++j) scanf("%g",ai].ans+j);
}
struct test {int n; float *ans;};
int nt,i,j;
struct test *a,*current;
printf("How many math tests? ");
scanf("%d",&nt);
a=malloc(nt*sizeof*a); /* enough space for nt test structures */
for(i=0;i<nt;++i) {
current=a+i; /* point at the i-th element of the array; no new object is created here! */
printf("How many questions are on test #%d? ",i);
scanf("%d",¤t->n);
current->ans=malloc(current->n*sizeof*current->ans); /* enough space for current->n floats */
printf("What are the answers? ");
for(j=0;j<current->n;++j) scanf("%g",current->ans+j);
}
struct test {int n; float *ans;};
int nt;
struct test *a,*current,*end;
printf("How many math tests? ");
scanf("%d",&nt);
a=malloc(nt*sizeof*a); /* enough space for nt test structures */
end=a+nt; /* points just past the end of a */
for(current=a;current<end;++current) {
float *fcurrent,*fend;
printf("How many questions are on test #%d? ",current-a); /* you can still get the index if you want */
scanf("%d",¤t->n);
current->ans=malloc(current->n*sizeof*current->ans); /* enough space for a[i].n floats */
fend=current->ans+current->n; /* points just past the end of current->ans */
printf("What are the answers? ");
for(fcurrent=current->ans;fcurrent<fend;++fcurrent) scanf("%g",fcurrent);
}
struct test {int n; float *ans;};
int nt;
struct test *a,*current,*end;
printf("How many math tests? ");
scanf("%d",&nt);
a=malloc(nt*sizeof*a); /* enough space for nt test structures */
end=a+nt; /* points just past the end of a */
for(current=a;current<end;++current) {
float *fcurrent,*fend,**fpp=¤t->ans;
int *ip=¤t->n;
printf("How many questions are on test #%d? ",current-a); /* you can still get the index if you want */
scanf("%d",ip); /* this assigns to current->n, so we'll have the number later, but we can also call it *ip now */
*fpp=malloc(*ip*sizeof**fpp); /* enough space for *ip floats */
fend=*fpp+*ip; /* points just past the end of *fpp */
printf("What are the answers? ");
for(fcurrent=*fpp;fcurrent<fend;++fcurrent) scanf("%g",fcurrent);
}
a[whatever
: a[2*i*i-3*j+42]
, a[askUserWhich()]
, a[phaseOfMoon()]
, a[pickRandomly()]
, etc. Each of those uses
pointer arithmetic to pick out an element for you.)x=1;
struct.y=1;
*p=1;
a.b.c.….z=1;
, which is not very interesting. The third choice gives all kinds of possibilities because dereferencing a pointer can give you another pointer or a struct as well as a normal variable: a[4]=1;
(because that's *(a+4)=1;
), getPointer()->a=1;
(because that's (*getPointer()).a=1;
), **(*myStruct.ptrMember->memOfTarget)->mem2ndTarget=1;
, etc.int i; int *p=&i; *p=42; printf("%d\n",i);
) are so anemic that they prevent seeing the true utility of the subject. --
Tardis (
talk)
15:09, 21 October 2010 (UTC)
Thanks for all of your replies! The one thing I kept seeing over and over was that I must use a struct to access this info, can't I do this instead?:
void * blob = malloc(sizeof(char *) + sizeof(int));
char * blobChar = blob;
int * blob = blob + sizeof(char *); //since the integer is 4 bytes after the char *
—Preceding unsigned comment added by Legolas52 ( talk • contribs) 21:40, 22 October 2010 (UTC)
void * blob = malloc(sizeof(char *) + sizeof(int));
char ** blobChar = blob; /* since it _points to_ a char * */
int * blobi=(char *)blob + sizeof(char *); /* can't do arithmetic on void * */
sizeof(char*)==4
everywhere?) The struct, as a language construct, exists so that this can be handled properly by the compiler. It also requires less typing and is more readable: struct {char *str; int len;} *s=malloc(sizeof*s);
…and that's it! We now already have s->str and s->len with no further work. --
Tardis (
talk)
23:32, 22 October 2010 (UTC)Hello. I am trying to compile emacs 23.2. After a successful ./configure, make gives me the following:
PS223:~/Downloads/emacs-23.2% make cd lib-src; make all \ CC='gcc' CFLAGS='-g -O2 -Wdeclaration-after-statement -Wno-pointer-sign ' CPPFLAGS='-D_BSD_SOURCE ' \ LDFLAGS='-Wl,-znocombreloc ' MAKE='make' make[1]: Entering directory `/home/rksh/Downloads/emacs-23.2/lib-src' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/home/rksh/Downloads/emacs-23.2/lib-src' boot=bootstrap-emacs; \ if [ ! -x "src/$boot" ]; then \ cd src; make all \ CC='gcc' CFLAGS='-g -O2 -Wdeclaration-after-statement -Wno-pointer-sign ' CPPFLAGS='-D_BSD_SOURCE ' \ LDFLAGS='-Wl,-znocombreloc ' MAKE='make' BOOTSTRAPEMACS="$boot"; \ fi; cd src; make all \ CC='gcc' CFLAGS='-g -O2 -Wdeclaration-after-statement -Wno-pointer-sign ' CPPFLAGS='-D_BSD_SOURCE ' \ LDFLAGS='-Wl,-znocombreloc ' MAKE='make' BOOTSTRAPEMACS="" make[1]: Entering directory `/home/rksh/Downloads/emacs-23.2/src' make[1]: *** No rule to make target `/usr/local/include/gtk-2.0/gtk/gtk.h', needed by `dispnew.o'. Stop. make[1]: Leaving directory `/home/rksh/Downloads/emacs-23.2/src' make: *** [src] Error 2 HPS223:~/Downloads/emacs-23.2%
What is going on here? It looks like there needs to be a rule to make gtk.h, but this can't be right? Anyone got any idea how to get round this? Thanks, Robinh ( talk) 08:58, 21 October 2010 (UTC)
OK, so I've been having some non-critical yet annoying problems with my LCD display (a Flatron W1934S, to be specific). The overall image appears fine, but there are some wavy patterns jizzing up on my screen, which can be seen especially on a dark background. Is it because of an unstable AC connection or something? Blake Gripling ( talk) 10:35, 21 October 2010 (UTC)
Hi, I have my phone blacberry 9500 storm, was using zero line of france, turkey, I'm staying on the contract has expired, other operators çalıştıramadığımdan, mep2 code entered incorrectly 10 times, mep2 does not turn on, I can not enter the MEP code. please help. Thank you.
my adres= [email removed] —Preceding unsigned comment added by 88.224.127.41 ( talk) 13:23, 21 October 2010 (UTC)
Hi! Why doesn't exist the 'end tran' keywords? the rollback statement must always immediatly follow the trasnsaction to rollback? t.i.a. -- 217.194.34.103 ( talk) 14:47, 21 October 2010 (UTC)
where is the rt clock and how the quartz is deformed in order to produce the regular square wave? t.i.a. -- 217.194.34.103 ( talk) 14:50, 21 October 2010 (UTC)
I've just downloaded a program called NetMeter to keep an eye on my internet usage. I'm in a hotel and have a daily limit of 1 GiB. I'm looking at the program now and my upload and download figures are increasing. Even though, to my knowledge, nothing is uploading or downloading. It says that I'm downloading 36 KiB/sec at the moment, and that I've downloaded 21 MiB in the last 30 minutes.
Some internet sites say that 5 GiB per month is enough to use Skype and YouTube. But according to NetMeter, I'd use 10 GiB a month just by leaving the machine connected to the internet for six hours a day; without even watching a single video or making a single call. What's going on?! — Fly by Night ( talk) 15:19, 21 October 2010 (UTC)
Windows Update maybe? I disabled it on my computer, but I think if you have it enabled it will automatically download new updates. Also, check which network interface the program is monitoring; if it's set to "all interfaces" it could be seeing network activity which isn't related to the internet, or could be seeing double the amounts depending on your setup. 82.44.55.25 ( talk) 15:55, 21 October 2010 (UTC)
Sigh, for "computer experts" you're pretty incompetent. @OP; netmeter is not designed to work with wireless, so it's picking up on every network packet between your wireless adapter and the router. The excess bandwidth you're seeing is just the two devices communicating with each other. A program designed to work with wireless would filter this out.
72.95.222.173 (
talk)
16:30, 21 October 2010 (UTC)
The usage graph in NetMeter has changed now that I'm using Skype. It was all red. Now there is a yellow sub-graph. It looks like the yellow is my usage and the red is something else. Maybe other people's usage or traffic between my computer and the router. I've just ended the call and the yellow part has vanished. Does anyone have any idea how to change the settings? — Fly by Night ( talk) 19:56, 21 October 2010 (UTC)
Say in php there was
echo "There are $number pages";
how could you get the script to put that into a .html file? 82.44.55.25 ( talk) 18:38, 21 October 2010 (UTC)
I have a long list of rent money paid, and the dates they were paid on. i.e. the spreadsheet has two columns. The tenant was supposed to pay a fixed amount on the 1st of every month, but actually paid the rent very irregularly. Some months were missed completely, some were paid late, a few may have been paid early. The tenant has to pay x percent compound interest on late payments, if they are paid more than fourteen days late.
The question is: how do I work out on a spreadsheet what the tenant owes, including interest? The problem is that the data has irregular and missing dates, so it will be much harder to calculate than if the dates were just regular dates one month apart. Not a homework question. Thanks. 92.15.29.194 ( talk) 20:11, 21 October 2010 (UTC)
N/A
in the date column. Then, assuming that we're starting on row 2 and that column A has the date the rent was paid and column B has the rent amounts and column C is the one you added in, put the following in cell D2: =IF((A2-C2)>14,B2*(1+Data!A$1)^((A2-C2-14)/365.25)-B2,0)
. This deals with the months when the rent was paid. For the months when the rent was not paid, put the following into E2: =IF(A2="N/A",B2*(1+Data!A$1)^((Data!A$2-C2-14)/365.25),0)
.I'm wondering how to deal with a missed payments. Supposing the tenant missed one payment in January but paid all other payments that year in full and on time. Should I calculate the interest due from the January until the present time; or should I regard the February and subsequent payments as late payments for the previous month? 92.29.125.8 ( talk) 11:05, 22 October 2010 (UTC)
As the comments above note, there are multiple ways of calculating compound interest when the debt is being sporadically incurred and repaid. If this is just an academic question, then the answer depends on the method described in the hypothetical credit agreement that both parties entered into at the beginning of the contract and (depending on whether the debtor is a consumer or a limited company, several acts of parliament). But your post (as ip 92.29.125.8) strongly suggests this is a real scenario, which means this question is veering off into the territory of legal and professional advice, which the reference desk absolutely does not provide. You should speak to a qualified accountant. I'm reluctant even to tell you which laws you might be breaking (lest I help you self-help yourself to Pentonville) but I definitely would not go sending an invoice or a demand until you've spoken to a qualified professional. -- Finlay McWalter ☻ Talk 17:15, 22 October 2010 (UTC)
This is about manipulating data with a spreadsheet and maths, no legal stuff involved. I could re-write it if you wish as a scenario in Cuckooland, where the teddy bears trade Smarties. 92.15.28.203 ( talk) 19:39, 22 October 2010 (UTC)
Computing desk | ||
---|---|---|
< October 20 | << Sep | October | Nov >> | October 22 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
From one of these...
...before disposal. Thanks, hydnjo ( talk) 00:25, 21 October 2010 (UTC)
I'm really kind of confused with pointers in C. Let's say you malloc a blob of memory:
void * blob = malloc(sizeof(char *) + sizeof(int));
and you use the blob to hold two things like this: | a char * | integer value |
so blob would point to the memory adress of the beginning of the blob of malloc'd memory.
If you made a pointer to point to it:
void * pointToBob = bob;
Could you use bob and pointToBob interchangeably?
Or what if you had
void ** pointToBob = bob;
How could you used that?
I'm confused how you could possibly use a pointer to a pointer to change a value in the originally malloc'd blob. I'd appreciate any help with this problem and any sort of general explanations on the questions of pointers. I feel like I don't understand much more than "a pointer holds an adress to a place in memory". Thank you very much :) —Preceding unsigned comment added by Legolas52 ( talk • contribs) 00:58, 21 October 2010 (UTC)
void * pointToBlob = blob;
makes pointToBlob have the same type and value as blob. However, void ** pointToBlob = blob;
will give you a compile warning, because a pointer to a pointer is not the same type as a pointer. But a more basic problem is that your malloc line is a thing that ought not to be done. In some systems, the "int" type must be aligned in a specific way in memory space, so it may not be possible to store an int at the place you think you are going to store it. This is simply bad code. Even if it works, referring to things in memory that has been allocated in this way is so ugly that I'm not even going to try to write it. If you want to store multiple different things in a single block of memory, create a struct to hold them.
Looie496 (
talk)
01:23, 21 October 2010 (UTC)void ** pointToBlob = blob;
is legal C and won't produce a warning, because C allows void *
to be implicitly converted to any other pointer type (though C++ doesn't). There's no deep logic to this; it's just a special exception intended to make malloc
easier to use. The result of this definition will be that pointToBlob
will point to the same memory block as blob
does, except that it will "think it's pointing to" a void *
. You could then store a void *
into the memory block through that pointer, even though you allocated space for a char *
, because those pointer types happen to be guaranteed to have the same size. But that's probably not what you intended. If you wanted a pointer to the blob
variable itself (which is a different thing from the memory you allocated), then you should have written pointToBlob = &blob
instead of pointToBlob = blob
.&foo
then you get a value that points to foo
, if you say *p
in an expression then you get the value of whatever p
points to, and if you say *p = (whatever);
then you change the value of whatever p
points to. For example, if you wrote void ** pointToBlob = &blob;
, then *pointToBlob = malloc(100);
would be the same as blob = malloc(100);
(they both write the result to the blob
variable). But if you wrote void * pointToBlob = blob;
and then pointToBlob = malloc(100);
, you would be assigning to the variable pointToBlob
, which is a different variable from blob
, so blob
would remain unchanged. Although those rules are simple, they're hard to think about. The reason seems to be that human beings are not good at separating the name of something from the thing itself. For example, what does pointToBlob
mean? Do you intend it to point to the variable named "blob", or are you thinking of the memory you allocated as the "blob" that it points to? This kind of ambiguity is what makes pointers difficult. The good news is that it gets easier with practice. --
BenRG (
talk)
02:16, 21 October 2010 (UTC)char *
and an int
like that. You can, however, do it like this:struct mystruct { char *p; int i; }; struct mystruct *blob = malloc(sizeof(struct mystruct));
blob->p
and blob->i
to refer to the char *
and int
values, assuming the malloc()
succeeded. You can easily check this, because if malloc()
fails, the resulting value will be a null pointer.
JIP |
Talk
12:09, 21 October 2010 (UTC)int n,i;
float *a;
printf("How many questions are on the math test? ");
scanf("%d",&n); /* give scanf() a pointer to n so it can assign to n through it */
a=malloc(n*sizeof*a); /* enough space for n floats; *a is a float, so sizeof*a==sizeof(float) */
printf("What are the answers? ");
for(i=0;i<n;++i) scanf("%g",a+i); /* a[i]==*(a+i), so a+i==&a[i] and we store into each in turn */
int nt,*nq,i,j;
float **a;
printf("How many math tests? ");
scanf("%d",&nt);
a=malloc(nt*sizeof*a); /* enough space for nt float _pointers_ */
nq=malloc(nt*sizeof*nq); /* enough space for nt ints */
for(i=0;i<nt;++i) {
printf("How many questions are on test #%d? ",i);
scanf("%d",nq+i);
ai=malloc(nqi*sizeof*ai]); /* enough space for nq[i] floats */
printf("What are the answers? ");
for(j=0;j<nqi];++j) scanf("%g",ai+j);
}
struct test {int n; float *ans;};
int nt,i,j;
struct test *a;
printf("How many math tests? ");
scanf("%d",&nt);
a=malloc(nt*sizeof*a); /* enough space for nt test structures */
for(i=0;i<nt;++i) {
printf("How many questions are on test #%d? ",i);
scanf("%d",&ai].n);
ai].ans=malloc(ai].n*sizeof*ai].ans); /* enough space for a[i].n floats */
printf("What are the answers? ");
for(j=0;j<ai].n;++j) scanf("%g",ai].ans+j);
}
struct test {int n; float *ans;};
int nt,i,j;
struct test *a,*current;
printf("How many math tests? ");
scanf("%d",&nt);
a=malloc(nt*sizeof*a); /* enough space for nt test structures */
for(i=0;i<nt;++i) {
current=a+i; /* point at the i-th element of the array; no new object is created here! */
printf("How many questions are on test #%d? ",i);
scanf("%d",¤t->n);
current->ans=malloc(current->n*sizeof*current->ans); /* enough space for current->n floats */
printf("What are the answers? ");
for(j=0;j<current->n;++j) scanf("%g",current->ans+j);
}
struct test {int n; float *ans;};
int nt;
struct test *a,*current,*end;
printf("How many math tests? ");
scanf("%d",&nt);
a=malloc(nt*sizeof*a); /* enough space for nt test structures */
end=a+nt; /* points just past the end of a */
for(current=a;current<end;++current) {
float *fcurrent,*fend;
printf("How many questions are on test #%d? ",current-a); /* you can still get the index if you want */
scanf("%d",¤t->n);
current->ans=malloc(current->n*sizeof*current->ans); /* enough space for a[i].n floats */
fend=current->ans+current->n; /* points just past the end of current->ans */
printf("What are the answers? ");
for(fcurrent=current->ans;fcurrent<fend;++fcurrent) scanf("%g",fcurrent);
}
struct test {int n; float *ans;};
int nt;
struct test *a,*current,*end;
printf("How many math tests? ");
scanf("%d",&nt);
a=malloc(nt*sizeof*a); /* enough space for nt test structures */
end=a+nt; /* points just past the end of a */
for(current=a;current<end;++current) {
float *fcurrent,*fend,**fpp=¤t->ans;
int *ip=¤t->n;
printf("How many questions are on test #%d? ",current-a); /* you can still get the index if you want */
scanf("%d",ip); /* this assigns to current->n, so we'll have the number later, but we can also call it *ip now */
*fpp=malloc(*ip*sizeof**fpp); /* enough space for *ip floats */
fend=*fpp+*ip; /* points just past the end of *fpp */
printf("What are the answers? ");
for(fcurrent=*fpp;fcurrent<fend;++fcurrent) scanf("%g",fcurrent);
}
a[whatever
: a[2*i*i-3*j+42]
, a[askUserWhich()]
, a[phaseOfMoon()]
, a[pickRandomly()]
, etc. Each of those uses
pointer arithmetic to pick out an element for you.)x=1;
struct.y=1;
*p=1;
a.b.c.….z=1;
, which is not very interesting. The third choice gives all kinds of possibilities because dereferencing a pointer can give you another pointer or a struct as well as a normal variable: a[4]=1;
(because that's *(a+4)=1;
), getPointer()->a=1;
(because that's (*getPointer()).a=1;
), **(*myStruct.ptrMember->memOfTarget)->mem2ndTarget=1;
, etc.int i; int *p=&i; *p=42; printf("%d\n",i);
) are so anemic that they prevent seeing the true utility of the subject. --
Tardis (
talk)
15:09, 21 October 2010 (UTC)
Thanks for all of your replies! The one thing I kept seeing over and over was that I must use a struct to access this info, can't I do this instead?:
void * blob = malloc(sizeof(char *) + sizeof(int));
char * blobChar = blob;
int * blob = blob + sizeof(char *); //since the integer is 4 bytes after the char *
—Preceding unsigned comment added by Legolas52 ( talk • contribs) 21:40, 22 October 2010 (UTC)
void * blob = malloc(sizeof(char *) + sizeof(int));
char ** blobChar = blob; /* since it _points to_ a char * */
int * blobi=(char *)blob + sizeof(char *); /* can't do arithmetic on void * */
sizeof(char*)==4
everywhere?) The struct, as a language construct, exists so that this can be handled properly by the compiler. It also requires less typing and is more readable: struct {char *str; int len;} *s=malloc(sizeof*s);
…and that's it! We now already have s->str and s->len with no further work. --
Tardis (
talk)
23:32, 22 October 2010 (UTC)Hello. I am trying to compile emacs 23.2. After a successful ./configure, make gives me the following:
PS223:~/Downloads/emacs-23.2% make cd lib-src; make all \ CC='gcc' CFLAGS='-g -O2 -Wdeclaration-after-statement -Wno-pointer-sign ' CPPFLAGS='-D_BSD_SOURCE ' \ LDFLAGS='-Wl,-znocombreloc ' MAKE='make' make[1]: Entering directory `/home/rksh/Downloads/emacs-23.2/lib-src' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/home/rksh/Downloads/emacs-23.2/lib-src' boot=bootstrap-emacs; \ if [ ! -x "src/$boot" ]; then \ cd src; make all \ CC='gcc' CFLAGS='-g -O2 -Wdeclaration-after-statement -Wno-pointer-sign ' CPPFLAGS='-D_BSD_SOURCE ' \ LDFLAGS='-Wl,-znocombreloc ' MAKE='make' BOOTSTRAPEMACS="$boot"; \ fi; cd src; make all \ CC='gcc' CFLAGS='-g -O2 -Wdeclaration-after-statement -Wno-pointer-sign ' CPPFLAGS='-D_BSD_SOURCE ' \ LDFLAGS='-Wl,-znocombreloc ' MAKE='make' BOOTSTRAPEMACS="" make[1]: Entering directory `/home/rksh/Downloads/emacs-23.2/src' make[1]: *** No rule to make target `/usr/local/include/gtk-2.0/gtk/gtk.h', needed by `dispnew.o'. Stop. make[1]: Leaving directory `/home/rksh/Downloads/emacs-23.2/src' make: *** [src] Error 2 HPS223:~/Downloads/emacs-23.2%
What is going on here? It looks like there needs to be a rule to make gtk.h, but this can't be right? Anyone got any idea how to get round this? Thanks, Robinh ( talk) 08:58, 21 October 2010 (UTC)
OK, so I've been having some non-critical yet annoying problems with my LCD display (a Flatron W1934S, to be specific). The overall image appears fine, but there are some wavy patterns jizzing up on my screen, which can be seen especially on a dark background. Is it because of an unstable AC connection or something? Blake Gripling ( talk) 10:35, 21 October 2010 (UTC)
Hi, I have my phone blacberry 9500 storm, was using zero line of france, turkey, I'm staying on the contract has expired, other operators çalıştıramadığımdan, mep2 code entered incorrectly 10 times, mep2 does not turn on, I can not enter the MEP code. please help. Thank you.
my adres= [email removed] —Preceding unsigned comment added by 88.224.127.41 ( talk) 13:23, 21 October 2010 (UTC)
Hi! Why doesn't exist the 'end tran' keywords? the rollback statement must always immediatly follow the trasnsaction to rollback? t.i.a. -- 217.194.34.103 ( talk) 14:47, 21 October 2010 (UTC)
where is the rt clock and how the quartz is deformed in order to produce the regular square wave? t.i.a. -- 217.194.34.103 ( talk) 14:50, 21 October 2010 (UTC)
I've just downloaded a program called NetMeter to keep an eye on my internet usage. I'm in a hotel and have a daily limit of 1 GiB. I'm looking at the program now and my upload and download figures are increasing. Even though, to my knowledge, nothing is uploading or downloading. It says that I'm downloading 36 KiB/sec at the moment, and that I've downloaded 21 MiB in the last 30 minutes.
Some internet sites say that 5 GiB per month is enough to use Skype and YouTube. But according to NetMeter, I'd use 10 GiB a month just by leaving the machine connected to the internet for six hours a day; without even watching a single video or making a single call. What's going on?! — Fly by Night ( talk) 15:19, 21 October 2010 (UTC)
Windows Update maybe? I disabled it on my computer, but I think if you have it enabled it will automatically download new updates. Also, check which network interface the program is monitoring; if it's set to "all interfaces" it could be seeing network activity which isn't related to the internet, or could be seeing double the amounts depending on your setup. 82.44.55.25 ( talk) 15:55, 21 October 2010 (UTC)
Sigh, for "computer experts" you're pretty incompetent. @OP; netmeter is not designed to work with wireless, so it's picking up on every network packet between your wireless adapter and the router. The excess bandwidth you're seeing is just the two devices communicating with each other. A program designed to work with wireless would filter this out.
72.95.222.173 (
talk)
16:30, 21 October 2010 (UTC)
The usage graph in NetMeter has changed now that I'm using Skype. It was all red. Now there is a yellow sub-graph. It looks like the yellow is my usage and the red is something else. Maybe other people's usage or traffic between my computer and the router. I've just ended the call and the yellow part has vanished. Does anyone have any idea how to change the settings? — Fly by Night ( talk) 19:56, 21 October 2010 (UTC)
Say in php there was
echo "There are $number pages";
how could you get the script to put that into a .html file? 82.44.55.25 ( talk) 18:38, 21 October 2010 (UTC)
I have a long list of rent money paid, and the dates they were paid on. i.e. the spreadsheet has two columns. The tenant was supposed to pay a fixed amount on the 1st of every month, but actually paid the rent very irregularly. Some months were missed completely, some were paid late, a few may have been paid early. The tenant has to pay x percent compound interest on late payments, if they are paid more than fourteen days late.
The question is: how do I work out on a spreadsheet what the tenant owes, including interest? The problem is that the data has irregular and missing dates, so it will be much harder to calculate than if the dates were just regular dates one month apart. Not a homework question. Thanks. 92.15.29.194 ( talk) 20:11, 21 October 2010 (UTC)
N/A
in the date column. Then, assuming that we're starting on row 2 and that column A has the date the rent was paid and column B has the rent amounts and column C is the one you added in, put the following in cell D2: =IF((A2-C2)>14,B2*(1+Data!A$1)^((A2-C2-14)/365.25)-B2,0)
. This deals with the months when the rent was paid. For the months when the rent was not paid, put the following into E2: =IF(A2="N/A",B2*(1+Data!A$1)^((Data!A$2-C2-14)/365.25),0)
.I'm wondering how to deal with a missed payments. Supposing the tenant missed one payment in January but paid all other payments that year in full and on time. Should I calculate the interest due from the January until the present time; or should I regard the February and subsequent payments as late payments for the previous month? 92.29.125.8 ( talk) 11:05, 22 October 2010 (UTC)
As the comments above note, there are multiple ways of calculating compound interest when the debt is being sporadically incurred and repaid. If this is just an academic question, then the answer depends on the method described in the hypothetical credit agreement that both parties entered into at the beginning of the contract and (depending on whether the debtor is a consumer or a limited company, several acts of parliament). But your post (as ip 92.29.125.8) strongly suggests this is a real scenario, which means this question is veering off into the territory of legal and professional advice, which the reference desk absolutely does not provide. You should speak to a qualified accountant. I'm reluctant even to tell you which laws you might be breaking (lest I help you self-help yourself to Pentonville) but I definitely would not go sending an invoice or a demand until you've spoken to a qualified professional. -- Finlay McWalter ☻ Talk 17:15, 22 October 2010 (UTC)
This is about manipulating data with a spreadsheet and maths, no legal stuff involved. I could re-write it if you wish as a scenario in Cuckooland, where the teddy bears trade Smarties. 92.15.28.203 ( talk) 19:39, 22 October 2010 (UTC)