#qi-hardware IRC log for Monday, 2013-04-01

whitequarkviric: sharc?00:33
whitequarklike an evil child of sparc and sh-4?00:34
wpwrakgrmbl   echo '#define usb urb' >>include/linux/usb.h02:07
wpwrakabout 80% of all failed compilations are because of that typo :-(02:08
viric_whitequark: I don't know. some dsp :)08:45
larscviric_: no08:56
larscwhitequark: short for super hyper architecture or something like that ;)08:56
larscit's a DSP from ADI08:57
qi-bot[commit] Werner Almesberger: fw/include/atusb/: move shared protocol definitions from ep0.h to atusb.h (master) http://qi-hw.com/p/ben-wpan/12d340108:57
qi-bot[commit] Werner Almesberger: atusb/fw/board.h: de-duplicate USB ID definitions (now originate from atusb.h) (master) http://qi-hw.com/p/ben-wpan/2d4387608:57
wpwrakSuper Harvard Architecture ;-)08:57
qi-bot[commit] Werner Almesberger: fw/include/atusb/ep0.h (USB_TYPE_VENDOR): avoid conflict with /usr/include/usb.h (master) http://qi-hw.com/p/ben-wpan/16dd76709:00
viric_super harvard architecture, no?09:10
viric_although super hyper sounds nice ;)09:10
larscyes, super harvard is correct09:20
kyakint array[100]; - is it a definition or merely a declaration?09:21
viric_'extern int array[100];' would be a declaration09:21
kyakso the memory gets allocated after this line of code, right?09:21
kyakok, i see09:22
larscif it is a global variable the memory is always allocated for the lifetime of the program09:23
viricalso, if in a function body, it's prefixed by 'static'09:24
viricbut if you have:    int f(int array[100])    // it's different :)09:25
kyakyep, it's a declaration of function 'f'.. But shouldn't it be  int f(int array[])?09:26
viricit has a slightly different meaning09:26
viricif it includes the 10009:26
kyakwhta is it?09:26
virichm I've to think this one09:26
larscso, for function parameters 'int array[X]' is the same as 'int *array'09:27
larscat least for the generated code09:27
larscbut I think the typechecker might complain if you pass a int array[3] to a function that expects a int array[2]09:28
virichm I don't think so09:28
viricFor bidimensional, it's more clear:     int x[10][]    is different than   int **x09:29
kyaklarsc: "the typechecker might complain" do you mean that the code won't compile (or give warnings)?09:30
kyakand then what's the difference between 'int *array' and 'int array[]' for function arguments?09:31
larscgive warnings, but it looks like i'm mistaken09:31
larscthe compiler compiles int array[3] as int *array09:32
larsckyak: I think none09:32
larscIt just looks nicer ;)09:32
viricI agree09:32
viricit can become a difference in more dimensions, as I think "int array[][]" doesn't work.09:33
lindi-well if it is array[3] then the compiler can assume that you are not going to access array[-1] or array[3]?09:33
viriclindi-: but I remember there was something in the spec about that09:33
viricmh there is also: void fun(char buffer[static 2048])09:34
kyakoh common.. what's that?09:34
kyak'static 2048' looks weird09:34
viricthat asks the compiler "please check that there will be at least 2048"09:35
viricthe compiler *may* then check.09:35
kyakso the compiler will check the caller? this seems too sophisticated for a compiler09:37
kyakviric: could you explain what's 'int **x'?09:38
virica pointer to pointers to int09:38
virickyak: do you know 'cdecl'?09:38
viricinstall it :)09:38
kyaknope, i don't know; i'll check it out09:38
viriccdecl> explain int **x09:38
viricdeclare x as pointer to pointer to int09:38
kyakoh, nice09:38
larscor cdecl.org09:39
kyakcdecl> explain static 204809:39
kyaksyntax error09:39
viricyou can't write partial declarations! :)09:39
kyaknah, it doesn't understand the complete one (given by you above) as well09:40
viricmh bad09:40
larscit doesn't understand function declarations at all09:41
kyakviric: so the multidimensional array is just a collection of pointers to simple arrays?09:41
virickyak: *that* multidimensional (int **x) yes.09:42
viricbut:    int x[2][3] isn't like that.09:42
kyakah yeah, int x[2][3] is in contigous memory, if i remember09:43
viriclike:    int f(int x[][3])09:43
kyakcan we write int x[2][3][4]?09:43
larscint a[2][3] and a[x][y] is like int a[6] and a[x * 3 + y]09:43
virickyak: the Ansi C spec I have is 554 pages long. Imagine.09:43
virickyak: what do you write?09:44
kyakviric: i'm currently one third through K&R, that's how much i know about ANSI C :)09:44
viric:) ok09:44
kyakviric: i'm just studying a little bit, not writing anything at the moment09:45
kyakviric: btw, can you send me that ANSI C spec? I have the txt version, but it's not very convenient09:45
viricok but don't tell anyone09:46
kyakeven the police?09:46
viricthe police may know already09:46
wpwrakint array[2]; is equivalent to extern int array[2]; if in a global scope or equivalent to auto int array[2]; if in local scope. it never defaults to "static"11:00
wpwrakfurthermore, if "extern" and without initializer, it can be both declaration and definition. the linker picks one and makes that the actual definition.11:01
wpwrakif one has an initializer, then it becomes the definition. if more than one has an initializer, you get an error11:02
viricyou can't have two modules, in global scope saying:     int array[2];11:02
wpwraktry it ;-)11:03
viricdamn c :)11:04
wpwrakit's perfectly consistent :)11:04
viricgcc works11:04
viricin tcc, it fails11:04
viricerror: 'array' defined twice11:04
wpwraknow we know which compiler complies to standards :)11:05
viricisn't it a linker thing?11:05
viricnot compiler11:05
wpwrakwell, the compiler has to let it pass11:05
viricI don't mean multiple "int array[2];" in a module11:06
viricI mean "int array[2];" in every module11:06
wpwrakyou could actually have   int array[2]; int array[2]; int array[2]; and shouldn't get any complaint11:06
wpwrakthere's no difference11:07
virichow not?11:07
wpwrakwhat you can't have is mire than int array[2] = { 0 };11:07
wpwrakmore than one11:07
viricok, gcc generates 'C' (nm naming) for "int array[2];"11:07
viricwhile tcc generates 'B'11:07
viricc has lots of dark corners11:08
wpwrakjust remember that you usually don't have to write "extern". then it all follows logically.11:09
wpwrakthe only case where you NEED extern is if you're in a function-local scope and want to access something global (and are too cool to declare it at a global scope)11:09
viricmaybe it's just about different versions of c?11:10
wpwrakyeah, those long before K&R may be different. and maybe once skynet takes over, it'll make some changes as well ;-)11:11
wpwrakand of course, non-standards-compliant compilers may also have some different ideas :)11:12
virichehe you feel very sure11:12
wpwraki think what confuses you is that you read "extern" as "this-is-a-declaration". this isn't what it means.11:12
viricwe've to report to tcc then :)11:12
wpwrakit's common style to say explicitly "extern" when declaring a global variable. to make it clear to the human reader. but for the (compliant) compiler, this bears no meaning.11:13
viricI'll try clang11:14
viricok, clang does 'right'11:20
wpwrakanything else would have surprised me :)11:27
whitequarkwpwrak: um, I think that you do11:30
whitequark`int a;` translates to a COMMON linkage, whereas `extern int a;` to EXTERN (or however it's named)11:31
wpwrakin a global scope, where would you see a difference ?11:33
whitequarkwpwrak: I'm fairly certain it has something to do with initializers.11:36
wpwrakyes. initializers change everything. they turn a declaration (which can implicitly become a definition) into an explicit definition11:36
whitequarkwpwrak: yes, and I think that a declaration with `extern` cannot implicitly be changed to a definition.11:43
whitequarkisn't that the point of `extern`?11:43
whitequark(in this context)11:43
wpwrakno.  also  int a;  (in global scope) mens exactly the same as  extern int a;11:44
wpwraktry it :) you can do it all in the same .c file11:44
whitequarkwpwrak: nope :) https://gist.github.com/whitequark/90f490693e8e16752acf11:47
whitequarkthe symbols have different linkage. actually, `extern int a;` for some reason does not appear in the symbol table at all.11:47
wpwrakfunny. but the effect is still the same. whether an unreferenced item actually gets placed in the object file is beyond the scope of the C standard :)11:52
whitequarkok ok :)11:52
wpwrakit's a bit surprising, though, that the compiler would actually make a difference here. not sure why. maybe it's for mixed-language programming11:53
kyakyou know what? you make me feel good :) now i really am sure that you can't learn C12:11
kyaka lot of dark corners, as viric said12:11
kyak"one can't learn C", that's what i meant12:12
kyakalso i have to read the above discussion again.. Got a bit lost12:13
kyakok, so int array[2]; is a declaration if it is in a global scope?12:15
wpwrakah no, there is actually a difference. it's not very clearly expressed in K&R 2nd ed., but "extern" removes the property of a declaration being a tentative definition. so what gcc does reflects this exactly.12:17
kyakwhat happens if i have int array[2]; int array[2]; and then have array[2] = { 0 };? Which one of them will be defined?12:17
wpwrakin other words, in global scope, you can always change "extern FOO;" to "FOO;" but you can only sometimes change "FOO;" to "extern FOO;"12:18
wpwrakkyak: there are three types:  extern int a; /* declaration */  int a = 0; /* declaration and definition */  int a; /* declaration and tentative definition */12:19
wpwrakyou can have any number of declarations and any number of tentative definitions but only zero or one (non-tentative) definition. and if you're actually using the thing, you need at least one definition, be it tentative or not.12:20
wpwrakso  int a; int a; int a; int a;  is okay12:21
whitequarkby the way12:22
wpwrakextern int a; extern int a; extern int a;  is okay too. but you don't have a definition yet. if you want one, you need either int a; or int a = something;12:22
kyakok, but how are tentative defintions work together?12:22
whitequarkwpwrak, you seem to like C, Unix tools and perversions12:22
whitequarkwpwrak: you'll like this description of Ruby's lexer: http://whitequark.org/blog/2013/04/01/ruby-hacking-guide-ch-11-finite-state-lexer/12:22
wpwrakthe linker merges the tentative definitions into one12:22
kyakwpwrak: ok, now it's more clear12:23
kyakis it how it's called in K&R - tentative definition? Or is it implicit definition?12:24
wpwrakthat's how K&R call it12:25
wpwrakwhitequark: it's always fun to lex languages where newlines act as terminators :)12:26
wpwrakespecially since you generally don't want to do the python thing :)12:27
whitequarkwpwrak: oh there's more12:44
whitequarkI especially like the joke about "(ab)using [lookahead] LALR(1) up to (1)"12:45
whitequark(also the dude who translated it is awesome.)12:45
whitequark*[lookahead in]12:45
sb0hi wolfspraul, sharism.cc is still down ...16:09
wpwrakthe killer easter bunny ate it :)16:14
kyaki continue to open new things for myself. How do you like this mixed variable/function declaration: double sum, atof(char []); Also it is interesting that we can declare functions inside a calling function16:43
kyakin fact, i don't know yet if it any different to declaring the function outside of the calling function (but in the same file scope)16:44
pcercueiIt is cleaner to declare it outside, I think16:45
kyakso it seems to be a matter of personal taste16:46
pcercueilarsc, I have a question16:56
pcercueilarsc: I want to create a joystick driver for opendingux, so that the buttons of the gcw0 return joystick events instead of key events. The front buttons could use gpio-keys with no problem, but the analog stick would have to be integrated as well on the driver; is there a way I can smartly re-use gpio-keys from another driver without duplicating all of its code?16:59
pcercueiand still having the front buttons and the analog appear on the same joystick device...17:01
wpwrakkyak: with local declarations, you risk creating homonymous but incompatible types17:23
kyakwpwrak: do you mean declaring a function that would shadow existing declaration? Wouldn't it be caught by compiler?17:55
wpwraki was thinking more of structs, enums, and unions.17:56
pcercueikyak: not if you use weak functions, I think17:56
kyaki don't think i understand you..17:56
wpwrakand shadows will be caught if -Wshadow is set17:56
kyakpcercuei: what is a weak function?17:57
wpwrakfox example this: http://pastebin.com/v4sYLSin17:59
wpwrakyou can make all sorts of variations of this theme17:59
pcercueikyak: it's a GCC feature (are you talking about C/C++?): a "weak" function is a function that can be redefined17:59
kyakwpwrak: let me take a minute to think about it :)18:00
kyakpcercuei: i see, it's an interesting concept. Some short googling says that it is specific to ARM18:00
wpwrakkyak: it's a bit of a brain twister ;-)18:01
pcercueikyak: hmmm I think it works on more architectures18:02
pcercueifrom the GCC manual: "Weak symbols are supported for ELF targets"18:03
kyakpcercuei: yea, the information i found is not about GCC compiler at all, sorry for confision :)18:06
kyakwpwrak: so here is your trick. You call the 'foo' function from main. Compiler knows it is a function because it is an expression followed by a left parentheses. You pass a 'bar' structure into the 'foo' function, and the 'bar' structure is also named 'foo' by some evil genius. This structure is global scope. What's interesting in 'foo' function is that you declare the 'foo' structure again in the parameter list.18:12
kyakthis last trick doesn't really work, the compiler returns error: incompatible type for argument 1 of 'foo'18:13
wpwrakyup. here's a version that looks less suspicious but has exactly the same problem: http://pastebin.com/b5QPEmwP18:17
wpwrak(also note the barrage of compiler complaints :)18:17
kyakand here''s a compilable version: http://codepad.org/pRQ9K5Qq :)18:23
wpwrakyes. get rid of the implicit local declaration of the struct and all works :)18:26
kyakwpwrak: here's a little trick for you: char abc[3] = "abc"; - what's going to be the size of abc and what would be inside?18:28
wpwraksize will be 3. content .. hmm. checking k&r ...18:30
wpwrakit's probably a special case18:31
wpwrakyup. A8.7 "As a special case [...]" :)18:32
kyakhm, actually it doesn't really explain in K&R18:35
kyakchar abc[] = "abc"; //abc size is 418:36
kyakchar abc[3] = "abc"; //abc size is 318:36
wpwrakit does :)18:37
kyaki'm reading the paragraph again :)18:37
kyakoh yes18:39
wpwraknice. killed the kernel so hard it didn't even make a sound :)18:54
qi-bot[commit] Werner Almesberger: fw/include/atusb/ep0.h: protect also USB_DIR_IN and USB_DIR_OUT (master) http://qi-hw.com/p/ben-wpan/3e749c318:57
qi-bot[commit] Werner Almesberger: atusb/fw/mac.c (handle_irq): only handle TRX_END; never fall back to seq ints (master) http://qi-hw.com/p/ben-wpan/60ee82b18:57
qi-bot[commit] Werner Almesberger: atusb/fw/mac.c (handle_irq): move frame reception to separate function (master) http://qi-hw.com/p/ben-wpan/d76bdf618:57
qi-bot[commit] Werner Almesberger: atusb/fw/include/atusb/usb-ids.h: remove (and adapt former users) (master) http://qi-hw.com/p/ben-wpan/dab0d1818:57
qi-bot[commit] Werner Almesberger: include/atusb/atusb.h: salvage cute explanation of 0x1540 from usb-ids.h (master) http://qi-hw.com/p/ben-wpan/ad70d7c18:57
qi-bot[commit] Werner Almesberger: atusb/fw/mac.c: queue frame reception if USB is busy (master) http://qi-hw.com/p/ben-wpan/65722d418:57
qi-bot[commit] Werner Almesberger: atusb/fw/usb/: enable MCU reset on USB bus reset after config selection (master) http://qi-hw.com/p/ben-wpan/9b2696b18:57
viricwpwrak: I fed the tcc list19:28
viricwpwrak: I found the mention in the ansi:
virichm sorry. ISO/IEC 9899:199919:30
wpwraknow the question is whether they interpreted it correctly :)19:32
wpwrakbecause ... if you declare it such that it's visible at the time of use, tcc will get it right19:32
viric6.9.2.2 is quite clear19:33
viricbut that's for c99 I guess.19:33
viricno idea of c1119:34
wpwrakso is the understanding that tcc is right or wrong ? from the thread it isn't quite clear19:36
wpwrakah, one more post :)19:37
viricyes, the last one19:42
viricthe key is 'tentative'19:42
wpwrakyup :)19:47
whitequarkplease do remember that tcc was originally written for IOCCC19:56
whitequarkthat is, Obfuscated C Code Contest.19:56
viricyes sure19:56
viricbut it evolved. :)19:57
wpwrakprojects.qi-hardware.com down, too ?20:23
qi-bot[commit] Werner Almesberger: ircstat/ML: update for 3/2013 (master) http://qi-hw.com/p/wernermisc/8eee09320:23
wpwrakah no, just a glitch20:24
Action: hellekin love glitch21:27
wpwrakyeah, the best part of false alarms is usually the moment when you realize they're false :)21:40
--- Tue Apr 2 201300:00

Generated by irclog2html.py 2.9.2 by Marius Gedminas - find it at mg.pov.lt!