journal
all ![]() | Rob is 20,118 days old today. |
Oct 2010 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Dec 2010 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 2009 jan feb mar apr may jun jul aug sep oct nov dec
2011 jan feb mar apr may jun jul aug sep oct nov dec |< << more >> >| |
Entries this day: Before_test Hard_test Lin_at_The_Pink_Cow Question_for_stackoverflow.com a_Talk_with_Lin vi Before test 12:10pm JST Friday 19 November 2010 (day 14849) So today's the 1 hour test I have with a company called Surgespace. It's supposed to be written using vi, which makes me not quite as happy as if they had said emacs. I *might* be able to use emacs here to remotely edit files there; just gotta remember the filename syntax. Ah, thanks Jeremy: /username@myserver.com:directory/file.txt In other news, ironically, my lower right shoulderblade features a knot below it, from a bit too much programming, preparing for this test. Gotta go get some foodage. permalinkHard test 4:08pm JST Friday 19 November 2010 (day 14849) Okay! So that was harder than I hoped. However, doing the preparation for the past couple of days *really* helped. I logged in as they wished and used vi. I solved the first one in about 20 minutes. It seemed quite fast, but when I saw the clock, I was like, "holy shit 20 minutes????" cause I had had a flash of taking a break before number 2, but no time for that!! I got about halfway, but I did not finish the second question in the remaining 40 minutes. I got the code for 1/2 of the processing done, and it compiled, but gave a segmentation fault when running. Dammmit. I know the error is tiny. I *really* hope they give a lot of "plus points" for writing in C. (They said they would give plus points, but I don't know how much that factors in.) The third question would have taken me over an hour, just by itself. Probably a day, actually, cause I'd need to do a lot of research. permalinkLin at The Pink Cow 5:49pm JST Friday 19 November 2010 (day 14849) Headed to The Pink Cow now to see Lin and her friend Sachiko. Turns out Mikako cannot go. permalinkQuestion for stackoverflow.com I've read several discussions of passing char * in C. [stackoverflow - passing-an-array-of-strings-as-parameter-to-a-function-in-c](http://stackoverflow.com/questions/486075/passing-an-array-of-strings-as-parameter-to-a-function-in-c#486095) [stackoverflow - how-does-an-array-of-pointers-to-pointers-work](http://stackoverflow.com/questions/1015944/how-does-an-array-of-pointers-to-pointers-work/1015970#1015970) [stackoverflow - pet peeve: char * are not arrays](http://stackoverflow.com/questions/423823/whats-your-favorite-programmer-ignorance-pet-peeve/484900#484900) [drexel.edu - C tutorial: char](http://einstein.drexel.edu/courses/Comp_Phys/General/C_basics/#character) Many of them include discussions of arrays, but I want to stay away from that. I'm writing a sample program to teach myself about the passing of `char *` and `char **` in C. This is an exercise in passing char *, without using (pointers to) arrays. Also no concerns for execution efficiency. :-) #include <stdlib.h> #include <stdio.h> #include <string.h> int get_args_works(int, char **, char **); int get_args_broken(int, char **, char *); char *get_string(int, char **); int main(int argc, char **argv) { char *string_works; char *string_broken; get_args_works(argc, argv, &string_works); get_args_broken(argc, argv, string_broken); printf("in main string_works (%p) = %s\n",string_works,string_works); free(string_works); printf("in main string_broken (%p) = %s\n",string_broken,string_broken); free(string_broken); } int get_args_works(int argc, char **argv, char **string) { *string = get_string(argc, argv); printf("in get_args_works %p string %s\n",*string,*string); } int get_args_broken(int argc, char **argv, char *string) { string = get_string(argc, argv); printf("in get_args_broken %p string %s\n",string,string); } char * get_string(int argc, char **argv) { int i; char *string; string = malloc(40); // placeholder in case -s switch not found below strcpy(string,"-s switch not found below"); for(i = 0; i < argc; i++) { if(argv[i][0] == '-') { switch(argv[i][1]) { case 's': // release above malloc(40) for "-s switch not found below" free(string); // make room for storing variable string = malloc(strlen(argv[++i]) + 1); // the argv just after -s strcpy (string,argv[i]); break; } } } return string; } You can also view the [same code on github](https://github.com/thunderrabbit/sea-review/blob/327bcda133ada7a124be423400e72fef997e5e5d/stackoverflow.c) The above code is somewhat self documenting. `main()` passes two variables as parameters to their respective `get_args()` functions. Each `get_args()` function calls `char * get_string(int, char **)`, using the exact same call. `get_string()` works fine; it does a `malloc()` and returns the pointer back to the calling function. That code works, and each `get_args()` function receives the return value as I expect. But then, when they return to `main()`, why does the doubly dereferenced pointer get back to main, but not the singly dereferenced pointer? I can see that if I dereference the pointer (`&XXXXXX_works`) when sending as a parameter, it works. But why? Isn't it already a pointer? Why does it need the "extra" (*) dereference when sending as a parameter? I'm hoping for a winning answer that explains how you (yes, you) conceptualize sending char * as a parameter vs receiving it as the function's return value. (*) it seems extra to me, but apparently it's not.permalink a Talk with Lin 12:33am JST Saturday 20 November 2010 (day 14850) She brought up a topic difficult to say but dear to her heart. "What's your vision? Do you have a vision for the future, where you want to be 10 years from now?" I said no at first, but that's not quite true. I have a vision of sorts (have a space where I can create art, receive clients for healing, and do meditation workshops), but I don't have a plan for how to get there. I get blocked at the money issue; how to find the money to get the space or build the place, etc etc.. but, I know ways to visualize the reality I want. Wende and I did it to find our house. I did it to find Lin. Write it down; bless it; feel it; manifest it. That's The Secret. So maybe if I reframe my idea so that I'm just looking for the right space I'll be able to find it more easily; I don't have to create it from scratch. Internet cafe now to snooze. I think it might be useful for me to learn vi. I can understand one of the arguments against emacs; it does require some finger contortions. permalinkvi 12:58pm Friday 19 November 2010 This is a little file I'm writing using vi, in preparation for a test I'm supposed to take online, using vi as the editor. I guess it's not so hard to just write lines in prose. I need to swap some stuff around. Okay, I'm going to take this line, copy it, put line numbers in front of its clones, and move them around. 01 Okay, I'm going to take this line, copy it, put line numbers in front of its clones, and move them around. 05 04 Okay, I'm going to take this line, copy it, put line numbers in front of its clones, and move them around. 06 Okay, I'm going to take this line, copy it, put line numbers in front of its clones, and around move. 03 Okay, I'm to take this line, copy it, put line numbers going in front of its clones, and them move them around. 02 Okay, I'm going to take this line, copy it, put line numbers in front of its clones, and move them around. put line numbers in front of its clones, and move them around. 04 Okay, I'm going to take this line, copy it, put line numbers in front of its clones, and move them around.permalink prev day next day |