24062010

   1 *       bgs100 [Jun 24 19:44:57] notices time!
   2 <bgs100>        [Jun 24 19:45:02] pedro3005 ?
   3 <pedro3005>     [Jun 24 19:45:10] yes
   4 *       bgs100 [Jun 24 19:45:22] assumes sedios was eaten by black hole
   5 <pedro3005>     [Jun 24 19:45:40] yeah, tragic
   6 <Snova> [Jun 24 19:47:33] we might see him again, but we'll have to postpone the lesson for a while...
   7 <bgs100>        [Jun 24 19:47:51] Haha
   8 <bgs100>        [Jun 24 19:49:11] -=-=-=-=-=-=-=-=-= C class begin, I guess. 40 minutes late. :P =-=-=-=-=-=-=-=-=-=-
   9 <bgs100>        [Jun 24 19:49:20] pedro3005, You asked for a relink? http://paste.pocoo.org/show/229638/
  10 <pedro3005>     [Jun 24 19:52:16] bgs100, ok, I understand up to line... 9
  11 <pedro3005>     [Jun 24 19:52:17] xD
  12 <bgs100>        [Jun 24 19:52:54] We start a for loop.
  13 <Snova> [Jun 24 19:53:08] well, I *think* I know how it works; it's quite elegant in its simplicity
  14 <bgs100>        [Jun 24 19:53:24] :|
  15 <Snova> [Jun 24 19:53:34] am I interrupting? :)
  16 <bgs100>        [Jun 24 19:53:38] No
  17 <bgs100>        [Jun 24 19:53:55] But having called it elegant and simple did slightly throw me :p
  18 <bgs100>        [Jun 24 19:54:08] it called*
  19 <bgs100>        [Jun 24 19:54:20] anyway, i is initalized to 0, and c to '\0' (which is 0 too :P)
  20 <Snova> [Jun 24 19:54:43] well, it's mostly just four lines... two of which are just loops
  21 <bgs100>        [Jun 24 19:54:56] Yeah.
  22 <Snova> [Jun 24 19:55:19] however
  23 <bgs100>        [Jun 24 19:55:25] What?
  24 <Snova> [Jun 24 19:55:42] I think, when the inner loop exits for EOF or \n, it will allocate an extra chunk
  25 <Snova> [Jun 24 19:56:05] that it doesn't need- so perhaps that realloc() call would do better before the inner loop, where it can also allocate the first chunk
  26 <bgs100>        [Jun 24 19:57:10] Wow, good idea. Fixes a bug and removes some code.
  27 <bgs100>        [Jun 24 19:57:34] Well, back to pedro3005
  28 <Snova> [Jun 24 19:58:15] to explain (sorry :p), it allocates memory in chunks of 20 bytes. "i" is the index into the memory that is the start of the last chunk (the one being filled in right now) and "j" is the index into /that/ chunk, so i+j is exactly where it's being filled in
  29 <bgs100>        [Jun 24 19:58:58] :P yeah
  30 <bgs100>        [Jun 24 19:59:25] And it keeps doing so until it hits an EOF or the specified delimiter.
  31 <Snova> [Jun 24 19:59:40] bgs100: also, the reason I called it "elegant and simple" is because if tasked to do this myself, I most certainly would not have come up with something so tidy (at least not on my first attempt)
  32 <Snova> [Jun 24 20:00:07] I'm not one for "complicated" loops, where "complicated" means just about anything more than one simple condition
  33 *       bgs100 [Jun 24 20:00:16] gives self star? :P
  34 *       Snova [Jun 24 20:00:53] gives bgs100 the Engineering Star
  35 <bgs100>        [Jun 24 20:00:54] pedro3005, Also, it takes the FILE so you can use it on any file open for reading (as opposed to just stdin).
  36 <bgs100>        [Jun 24 20:00:58] Yaaay
  37 <Snova> [Jun 24 20:01:11] there is very little to take away from this :p
  38 <bgs100>        [Jun 24 20:02:19] pedro3005, And the other functions are just little convenience functions that give it parameters one might use often.
  39 <bgs100>        [Jun 24 20:02:44] and then the purpose of main was just a test.
  40 <bgs100>        [Jun 24 20:03:23] pedro3005, Okay?
  41 <pedro3005>     [Jun 24 20:03:27] bgs100, how can I put it in some header file so I could do something like #include <bgs'hack> ? :P
  42 <Snova> [Jun 24 20:03:35] you wouldn't
  43 <Snova> [Jun 24 20:03:40] headers should not contain code
  44 <bgs100>        [Jun 24 20:04:06] Snova, Remember when I tried to use include like import? :P
  45 <Snova> [Jun 24 20:04:20] not exactly; were you including C files?
  46 <bgs100>        [Jun 24 20:04:27] Yes
  47 <bgs100>        [Jun 24 20:04:46] Or naming C files with .h instead of .c
  48 <Snova> [Jun 24 20:04:59] well, technically .h files are C :p
  49 <bgs100>        [Jun 24 20:05:08] *rolls eyes*
  50 <pedro3005>     [Jun 24 20:05:54] bgs100, so then how do you import stuff in C?
  51 <bgs100>        [Jun 24 20:06:03] include*
  52 <pedro3005>     [Jun 24 20:06:19] import, include, use, get, whatever
  53 <bgs100>        [Jun 24 20:07:33] pedro3005, Header files are used to declares the functions in C source/object code. When you #include a file, it's pretty much put there in your program. You then compile your code with the code you're using, or the object code. Unless you're using special .so type files, which I don't know much about.
  54 <bgs100>        [Jun 24 20:07:39] declare*
  55 <bgs100>        [Jun 24 20:07:45] Snova, Correct? :p
  56 <pedro3005>     [Jun 24 20:08:23] So... they DO contain code?
  57 <bgs100>        [Jun 24 20:08:52] Er
  58 <bgs100>        [Jun 24 20:09:04] If you consider just declarations code
  59 <pedro3005>     [Jun 24 20:09:28] it's not cheese, is it?
  60 <pedro3005>     [Jun 24 20:09:31] >.>
  61 <bgs100>        [Jun 24 20:09:42] lolwut
  62 <pedro3005>     [Jun 24 20:10:01] so let me reformulate
  63 <pedro3005>     [Jun 24 20:10:14] how do I stick this non-code into a header file?
  64 <bgs100>        [Jun 24 20:11:36] You put it in there.
  65 <Snova> [Jun 24 20:11:49] pedro3005: you know how you were able to compile code that called a nonexistent function, but couldn't link it?
  66 <pedro3005>     [Jun 24 20:12:06] how?
  67 <Snova> [Jun 24 20:12:14] you did it the other day; getcar()
  68 <bgs100>        [Jun 24 20:12:25] That is, the function declarations. You'll need to remove the main() function.
  69 <Snova> [Jun 24 20:12:40] the purpose of a .h file is simply to inform the compiler of the existence of certain functions; their name and signatures
  70 <Snova> [Jun 24 20:12:57] all .c files are compiled separately without any further knowledge of each other than the function names they contain
  71 <pedro3005>     [Jun 24 20:13:02] so where is the code for printf()?
  72 <bgs100>        [Jun 24 20:13:02] And variables?
  73 <Snova> [Jun 24 20:13:27] the reason is that just parsing tons of C code is expensive, so the idea is to build each one separately with the bare minimum of information necessary for it to work
  74 <Snova> [Jun 24 20:13:31] that too
  75 <Snova> [Jun 24 20:13:39] pedro3005: /lib/libc-2.11.1.so
  76 <pedro3005>     [Jun 24 20:13:56] Snova, so what I'm really looking after is a .so file?
  77 <Snova> [Jun 24 20:13:58] stdio.h contains exactly this: extern int printf (__const char *__restrict __format, ...);
  78 <Snova> [Jun 24 20:14:06] i.e. there is no code anymore
  79 <bgs100>        [Jun 24 20:14:43] brb
  80 <Snova> [Jun 24 20:14:45] printf()'s *actual* source code implementation has long since been discarded; what you have left is compiled code in libc and its definition in stdio.h
  81 <Snova> [Jun 24 20:15:02] said definition is only necessary so that the compiler can tell you when you're using it wrong
  82 <pedro3005>     [Jun 24 20:15:23] :/
  83 <pedro3005>     [Jun 24 20:15:31] is there any way to do what I want?
  84 <Snova> [Jun 24 20:15:54] what did you want?
  85 <pedro3005>     [Jun 24 20:16:12] put these functions somewhere so I can "import" them later
  86 <Snova> [Jun 24 20:16:27] you would put that code into a .c file, and the function definitions into a .h file
  87 <pedro3005>     [Jun 24 20:17:26] and what exactly is the function definition?
  88 <Snova> [Jun 24 20:18:04] char* fgetdelim(char delim, FILE* fp);
  89 <Snova> [Jun 24 20:18:09] char *getdelim(char delim);
  90 <Snova> [Jun 24 20:18:13] etc.
  91 <pedro3005>     [Jun 24 20:18:30] so I put these things in a .h file
  92 <pedro3005>     [Jun 24 20:18:35] and the code in a .c file
  93 <pedro3005>     [Jun 24 20:18:38] just that?
  94 <Snova> [Jun 24 20:19:28] yes
  95 <pedro3005>     [Jun 24 20:19:48] don't I need to specify in the .h file where is the .c file?
  96 <Snova> [Jun 24 20:20:21] no
  97 <Snova> [Jun 24 20:20:28] because you have to compile and link the .c file yourself
  98 <Snova> [Jun 24 20:20:41] .h files are just definitions for the sake of the compiler
  99 <pedro3005>     [Jun 24 20:21:05] and what does "link" mean?
 100 <Snova> [Jun 24 20:21:38] the usual process of combining every library you're actually using into a binary, which I suspect has been transparent to you until now
 101 <bgs100>        [Jun 24 20:22:06] back
 102 <Snova> [Jun 24 20:22:12] the usual process of building C code consists of compiling each individual .c file into a .o file ("object code") and "linking" all of those .o files, along with necessary libraries, into your finished binary
 103 <Snova> [Jun 24 20:22:32] putting bgs100's code into a separate .c file essentially gives you your first (I think?) multi-file C program
 104 <bgs100>        [Jun 24 20:22:38] Snova, Yeah, I was going to discuss this in the 3rd party libraries section which never happened
 105 <Snova> [Jun 24 20:23:02] you *can* compile it all in one go; gcc will let you simply pass it a list of .c files and it will do it all for you without generating intermediate .o files (well... oh, never mind)
 106 <Snova> [Jun 24 20:23:16] hm, wish seidos was here, else i'll have to explain this twice
 107 <bgs100>        [Jun 24 20:23:20] lol @ never mind :P
 108 <pedro3005>     [Jun 24 20:23:49] well, we can wait for him
 109 <Snova> [Jun 24 20:24:10] I would have to go through various other compilation phases, /tmp files, and pipelining for that "well..." to make sense :p
 110 <bgs100>        [Jun 24 20:31:48] heh
 111 <pedro3005>     [Jun 24 20:56:28] bgs100, Snova, seidos is here
 112 <bgs100>        [Jun 24 20:56:48] :O
 113 <bgs100>        [Jun 24 20:56:54] seidos, pingeth
 114 <seidos>        [Jun 24 20:56:54] hola
 115 <bgs100>        [Jun 24 20:57:04] seidos, Hi, you've missed a bunch :P
 116 <seidos>        [Jun 24 20:57:23] yeah, I still haven't read the logs from the last class
 117 <seidos>        [Jun 24 20:57:38] I guess just distracted by other problems
 118 <bgs100>        [Jun 24 20:57:51] Ah...
 119 <bgs100>        [Jun 24 20:57:59] well go ahead and read those logs then :P
 120 <seidos>        [Jun 24 20:59:32] oh, I have a question.  can one use scanf to accept string input?
 121 <pedro3005>     [Jun 24 21:02:35] bgs100, +1 to that question
 122 <bgs100>        [Jun 24 21:02:45] Yes.
 123 <bgs100>        [Jun 24 21:02:56] But it only gets up to a whitespace
 124 <bgs100>        [Jun 24 21:04:29] It's the "%s" format.
 125 <bgs100>        [Jun 24 21:04:41] char string[21];
 126 <bgs100>        [Jun 24 21:04:50] scanf("%s", &string);
 127 *       duanedesign [Jun 24 21:05:36] waves ay everyone
 128 <bgs100>        [Jun 24 21:05:52] hai
 129 <pedro3005>     [Jun 24 21:06:57] hey duanedesign
 130 <seidos>        [Jun 24 21:07:46] ah %s, never would've guessed that
 131 <seidos>        [Jun 24 21:07:52] thanks bgs100
 132 <bgs100>        [Jun 24 21:11:33] np
 133 <bgs100>        [Jun 24 21:11:38] seidos, s is for string :p
 134 <duanedesign>   [Jun 24 21:15:14] what would be the differences between the integer variables:  int, short, long
 135 <Snova> [Jun 24 21:18:33] size
 136 <Snova> [Jun 24 21:18:41] between int and long, possibly nothing
 137 <Snova> [Jun 24 21:19:06] short is 16 bits and int is 32; long is 32 and /might/ be 64 on 64-bit machines... not sure on that; integer sizes can be unreliably
 138 <Snova> [Jun 24 21:19:27] unreliable*
 139 <duanedesign>   [Jun 24 21:32:23] in C does the array index start at 0?
 140 <Snova> [Jun 24 21:32:55] yes
 141 <Snova> [Jun 24 21:33:09] most languages do, actually; the exceptions are rare and rather odd
 142 *       duanedesign [Jun 24 21:33:51] nods
 143 

learners/24062010 (last edited 2010-06-26 05:03:19 by 117)