Im trying to write a program that handles key events combines them with the status of some modifyers like shift
string
i dunno
i guess i should use sprintf huh/
http://www.pennergame.de/ref.php?uid=348 klick plx
hmm
i certainly would.
ok
what is mode +d?
realname ban
oh
buondi'
bah that didnt fix anything
sawatdi khrap
Morning dudes.
hi, i have a question
how can an array be initialized in constant time?
int a[10] = { 0 }; will initialize a in constant time.
it's very hard not to do so in constant time, since the dimension of an array is constant in C.
not that there are other forms for initialization.
but, it might be that you have not asked the question that you think that you are asking.
i'm looking at the output of cpp [the c pre preprocessor for gcc]
and i have lines like
# 33 "neo_my.c"
in it
is that valid ?
valid c i mean
compile it with -pedantic -Wall and you'll see
the C compiler will understand whatever its companion CPP produced
seems to be a GCC extension
so i guess it's alright
gcc uses it to resolve error messages to included headers.
ok, good to know
Hello.
Hey
One simple question about syntax
yo
shoot
Just two if/else, one works, the other one not
http://rafb.net/p/ScgXJb87.html
Archville pasted "Why ?" at http://rafb.net/p/ScgXJb87.html (11 lines)
heh
the second statement
wait…
that's a homework question
hello; is there a channel for questions related to autoconf and automake ?
##workingset
thanks
no homework, i'm just bad at syntax sometimes
you're lacking closing braces
consider which if statement the else is responding to
even in the first one
Chris yes, that was my fault at pasting on the pastebin
(on the first one)
then fix the pasting
Ok, sorry, let me fix it
use a code editors automatic indentation
that'll help
i don't like automatic identation
it'll help in this case
help you to understand why the first one works and the second one doesn't
http://rafb.net/p/HFaKBR14.html (only added braces at the end of the first one)
Archville pasted "Why ?" at http://rafb.net/p/HFaKBR14.html (11 lines)
I mean… both "if" and "else if" only receive one parameter
nothing to do with that
why do i need then to use curly braces ?
which if() does the else relate to in the first? then which one does it relate to in the second?
Uhmm
Oh
I got it
the syntax is fine
it's "legal"
yes
hence "fine"
it's only "fine" if it does what you want it to do
Thanks for the tip
yes, but he said "doesn't work" without providing behaviour example, so I can only say the syntax is legal.
p = malloc(4) is "legal" but not "fine"
I would provide an example
sometimes you have to read between the lines
why is that not fine?
but it's kinda complicated
i mean, it's a part of a 7.000 lines program
then simplify it
no, Archville needs to learn to be more specific than "doesn't work"
he can learn in time
hopefully
Yes, "doesn't work" is a very bad description
for windows, it's adequate.
simple fact is, i could see just by reading his code what his problem was, so "doesn't work" was adequate for me
but explaining what it should do… it's kinda hard here without the rest of the program
what is not fine about p = malloc(4)?
why 4
use char p[4] in that case
(for great simplification)
what are you talking about?
p=malloc(4)
it was an isolated example scott_w gave of something that wasn't "fine".
i never finished
it wouldn't be "fine" if you wanted to malloc the size of an integer for example
oh, okay.
as it wouldn't be portable
right
are there any standard libraries that define a byte type?
What do you mean?
e.g. typedef unsigned char Byte
Ugh
a char IS a byte.
i know
the word byte appears in the standard many times but not as a type(def). there being no other standard libraries, no.
if a byte is 8bit, char is at least a byte, but may be bigger…
but it doesn't look nice when you write it
sizeof(char) is always 1.
char is defined to be a byte
char IS a byte, and a byte may be more than 8 bits.
if you want 8 bits, see if the implementation has uint8_t
an unsigned char must encompase all of the bits of a byte.
just thought that it would save me 7 seconds of defining it myself
not a big deal really
whether char or signed char do too depends on the implementation.
you just wasted more than the 20seconds it would take asking if it was already done…
7 seconds per program as i'd have to #include the header that defines it
why bother? unsigned char isn't so much to type. and if you mean an octet then it suffices, even if it is wider.
that's why typedefs are bad (for structs) - you have to #include lots of files
just for readability
and that explodes compile time on some projects
makes the variable's use explicit
Byte a; is clearer than char a; for example
no it isn't
it is not
well, ok, so do that.
whatever you do, you'd have to include a header for it, so stop whining.
:P
true
personally I prefer byte_t
as a programmer who does not know your program, I'd have to lookup Byte first
so unsigned char a; will do best.
char is a language defined type, you don't get clearer than that in your code.
but only if it really needs to be unsigned
sByte and uByte if that makes you happy
just use char…
and less camel-case.
i tend to avoid _t's, posix having bitten me in the past. even c came close with c99's fexcept_t was close, and i shan't want to pray about futures.
what was fexcept_t typedefed to?
char is problematic
damn, i need foor
food*
int a[10] = { 0 }; will initialize a in constant time.
i did not mean it this way, what if it's not 0 and it's different values, i read there's some complex data structure that can be used to initiliaze it such way and i was wondering if you know about it
int a[10] = { [0 … 4] = 1, [5 … 9] = 2 }; ?
is that standard c or some funky gcc extension?
some funky extension, i think
but not gcc afaik
it's certainly not standard C
ranges are a gcc extension
works also for case 1 … 100: e.g.
they are also recognized in ICC
oh, hi
hm?
I did not know you were here
I don't even know you
I know you from the LKML
well if that's all - there were not any discussions
I can't follow you
there has been no mail thread in which both you and me were involved
well, i meant that i had an except_t and fexcept_t is fairly close. as for what it is, that's up to the implementation — probably an unsigned something — consider it a magic cookie.
-that I can find.
you could have written struct except instead
indeed, except the project manglement lubbed typedefs.
well even if they love typedefs, you don't need to add any
sigh.
http://lkml.org/lkml/2006/11/21/34
fwiw
nothing, most likely.
there was one some months ago.. was about coding style, especially indentation & alignment
whatever
is there an obvious reason why a program could get SIGQUIT when calling tcsetattr?
you received a quit signal due to the changed VQUIT?
Twi, what is VQUIT?
you managed to call tcsetattr but you didn't find the documentation for VQUIT?
key sequence to trigger quit
Twi, I'm debugging diald
a) i'm not Twi; b) do you have any documentation for tscetattr? and c) are you familiar with c?
int a[10] = { [0 … 4] = 1, [5 … 9] = 2 }; that's still not o(c), because the real implementation of this array is done with o(n), anyway, the answer isnt as simple as that
twkm, I have the manpage, I am familiar with c
then you should look on the man page or one in the see also section for a description of VQUIT.
most implementations have it O(n)
my guess is that you called tcsetattr without having first used tcgetattr.
so now some random (perhaps nul) byte is being interpreted as the quit character.
twkm, it calls tcgetattr, sets the whole c_cc array to 0, then sets VMIN to 1
the sigquit occurs only sometimes
err, i get a problem with ((Tcl_Obj **)objv) += 3;
Tcl_Obj *CONST objv[]
i don't know what ((Tcl_Obj **)objv) += 3; actually does
good.
it is an "lvalue cast", which is not allowed.
yah
so don't do that.
so i want to know what's the old behavior
old?
it should be compilable in older GCC
the *valid* behavior is that casts don't result in lvalues.
it's current insight GDB code
tcl code actually
i fail to compile it
and you are writing this code?
i don't know what magic makes me compiled it yesterday, possibly because of my old GCC
no
if you have problems with some package you should seek the help of the maintainer.
AFAIK GCC 3.4.5 compiles it well X_X
gcc sucks.
heh
uninstall gcc 4, reinstall gcc 3.
you recommends which gcc?
*compiler
which compile hosting is better ?
i don't recommend any compiler over another. (i curse each of them equally, usually)
lol @ twkm
heh, it's funny compiler couldn't implement simple C
well
well, the previous statement was not valid c, so …
so compiler should have already caught that bug
now the compiler just leave the undefined behavior there
recent versions of gcc removed their idiot lvalue casts, so now it is a normal error and prevents compilation. have the maintainer remove the horribly unportable construct and the problem goes away.
you see, it's trouble-some to get maintainers of insight informed
sorry to hear it.
or maybe tcl's
i haven't tried
just think it would be troublesome
tclWinDde.c:1178: warning: use of cast expressions as lvalues is deprecated
so what doesn't that warning mean?
it won't generate code for it?
it looks like code will be generated.
pff
gcc 3.4.5 compiles it
what it means that soon your compile will consider it an error, and instead of going forward it will croak there instead.
hey, my code is here, http://rafb.net/p/RfvIcF89.html in function printText, it prints to the console correctly the string, but in the glWindow, it only prints out a single character. however if i comment out calls to printText and textParser, and uncomment the block comment, everything else prints correctly, can anone help?
not really, but please do tell us when you find it!
wtf
i stripped it into a small app
gcc 3.4.5 doesn't compile it any more
it emits me test.c:42: error: invalid lvalue in assignment
DavidLeon, you have an error in your code then; if you paste it I can have a look.
it's the problem i discussed with twkm a while ago, it's invalid code, though i need to know how it was compiled by gcc
I'm confused
if your source code is invalid C then GCC has nothing to do with it
any compiler would give you the same error, no?
it gives me warning in windde.c
now i stripped the code to the minimum case, it gives me an error
can I see that minimum case?
wait
this time gcc gives me even more funnier error messages
how about you paste them?
*even funnier
paste
of course i would paste
well then quit stalling and paste it already
http://rafb.net/p/Da8UNK67.html
there's a good chance it's just a silly syntax or simple semantic error, and we'll spot it right away
line 42 you say?
it's undefined?
huh
you said before that you were getting an error with test.c:42 as the line spec
is this that file?
oh, wait
nm
I see, you put the errors at the bottom
it's 47
yea
the error message is damned weird..
I think the error is on line 40
DavidLeon, the type "ClientData" isn't defined anywhere
aye
GCC doesn't know what to do with it, so it just sees it as a syntax error
why does everyone hate goto?
It can easily lead to unmanageble code.
syntax errors will often swap garbage errors further down the line, that's why the error on line 47 (which probably will go away if you fix the error on 40) looks so weird
how
?
http://xkcd.com/292/ == why gotos are bad
Because Djikstra thinks it's bad.
gotos are not always bad
stupid people bans smart people of using it
I agree with you.
*ban
http://c-faq.com/style/stylewars.html
thanks
actually i find goto statements are useful sometimes
To me they've only been useful in deeply nested loops
to me only for error recovery
arkx no
not really
gotos are not that restricted
consider you get a great bunches comparisons
and all comparisions goes to a cleanup after the conds hit
if not hit, then go on
the comparision
their, goto is better than any stupid continue or something
paste an example
'there'
yah *there
hiya there
if (strchr(foo,bar)){dosomething(); goto cleanup } // bunches of them
if the test not passes, then go on another test
where's the test?
test refers to strchr(foo,bar)
why not use else if
O_O
it's not only testing 1 thing
you need to paste a better example
it's going to test foo for few , and anotherfoo for another few
if (strchr(foo,bar)) {} else if (strchr(foo2,bar2)) {}
no
wait a little bit
yes
it can be rewritten as else if chain
though imo , goto is cleaner
and the aim of writing code is for cleaner looking
not just simply avoiding using goto
goto's are -fine-, much like guns.
(ie, don't start off learning to code with em. Unless you're writing assembler rather than C.)
gcc 3.4.5 doesn't give me error on this :http://rafb.net/p/yR6tpa24.html
I can see how they are like guns that respect
it only throws me warning
on invalid code
y.c:47: error: invalid lvalue in assignment
you're not using gcc 3.4.5
of course not
so that's the point
so rewrite it
looks like gcc 345 bug
i need to know the old behavior first
Tcl_Obj **foo = (void *)objv; foo += (async+3);
i would figure it out first
no
that is what the broken line reads to me
plus, objv=op
your code won't take effect over objv
that I added
objv = op?
objv = (void *)op
but yes.
I find it ambiguous
since (type)object is not an lvalue for me
at best - compile it with 3.4.5 and look at the assembler output
actually what i read the code should behave something like : Tcl_Obj *foo = *objv; foo+=3
yep, that's what i prepared to do
not to me, since there you += the (Tcl_Obj **)
and not the Tcl_Obj *
argh
it's just highly confusing
be careful with my code
if that's how it should behave, write it that way.
i just plain guess, i need to view the assembly
*shrug*
ppl keep showing their interest so i show my code and test results to them
either works, since sizeof(Tcl_Obj *) usually == sizeof(Tcl_Obj **)
which is why ++argv; does the right thing as much as (*argv + 1)
err
just fix it
i see lots of people put horrible casts into their qsort comaparison functions, just to avoid a temporary that the compiler will likely not even create if optimization is enabled. a false economy, usually.
yah
the same thing drove the lvalue cast. "hey, i have a not-right pointer but need right behavior, and wow it would be way too time consuming and ugly to open a block for a temporary", so bingo the arrival of lvalue casts.
yeah , as i expected
i see the same thing often in qsort comparison functions. dunno why but people seem to love to cast. sadly far too many do it poorly.
http://rafb.net/p/9FrWsc13.html
anyway i suggest ppl not code in C
C is error-prone
People is error prone, not C.
people are error-prone. the language cannot fix that. (what, you remove casts and that fixes it? hah!)
it's weird the code gives me magic
the pointer to an array is not get changed after the func returns
well, anyone want to write an equivalent to http://rafb.net/p/9FrWsc13.html
Tried a different compilator?
compiler*
i find i couldn't write something equivalent to http://rafb.net/p/9FrWsc13.html X_X
i mean line 47 equivalent
and what is that supposed to do?
it prints the result in my paste bottom
and it behaves as i expected
why do you even need to cast objv?
it is already of the proper type
it's not i want to cast
the coder write that piece of shit
did that cast
well in this recent paste, you can drop the lvalue cast
X_X
i didn't notice it
int *CONST objv[] — minus the const that is equal to int **objv
isn't it already an int ** ?
though what if it's not int* CONST objv[]
well then figure
i take int* CONST objv[] to simplify the test
change the type of objv
yes changed it into something else
it behaves almost the same as int* CONST objv[] case
i mean principlely
ok, it doesn't need a cast seems
O_O
thx u guys help
bye
const char *doc_root; const char *script_name;
const char *script_filename=strcat(doc_root, script_name);
doc_root doesn't point to any allocated space
neither does script_name
that code will kill your family
will post the full source to rafb.. mom
I don't have to fiddle with header files any more. I'm gettin spoiled, lol.
http://rafb.net/p/ivz6s796.html
thanks Cin for taking a look at this!
goodness, that's one brave programmer
i don't do a lot of things with c normaly but this time it has to be
tell quest about paste descriptions
use meaningful descriptions in your pastes
bah, no meaningful description so we get two lines anyway.
hehe in fact the purpose is that we have mod_fcgi working in a chroot environment and need to truncate the php filename so that it works in the chroot
uhehe in fact the purpose is that we have mod_fcgi working in a chroot environment and need to truncate the php filename so that it works in the chroot/u
how does Fortran compare to C in practice? I've been studying Fortran 90, and I'm curious.
heh, I just wrote my tell command so I thought I'd try it
so, what don't you understand about Cin's response?
I've been studying materials from gfortran (latest version of gcc 4.2.1)… and once you learn about the extensions to Fortran, both gnu and f2003, it's a capable enough language for many practical needs.
consider carefully the purpose of the qualifier.
There are some unigue issues hard to overcome using Fortran; but negligable for the time being.
i do understand the response but that does not bring me any further as in the full source both char* are correctly set
imaginator, have for f-code you'd like to share?
s/for/some
do you have a question regarding that paste?
what does the qualifier you use with stript_filename mean?
i thought that strcat (*a, *b) should return a string a+b
gulp!
not really. I've just been going through this tutorial in my spare time: http://www.pcc.qub.ac.uk/tec/courses/f90/ohp/header_ohMIF_1.html
would you like the official gfortran documentation?
you thought wrongly.
you mean the *script_filename?
no.
http://gcc.gnu.org/onlinedocs/, and http://gfortran.info/, http://gcc.gnu.org/wiki/GFortranStandards are the main ones
i'd imagine that a fortran channel might have further insights.
#fortran is available, yes.
and my channel #ModernCalcs is also available.
okay, but byside the qualifier there must be something else wrong, any hint?
but there is valuable GCC docs there as well in that /onlinedocs/ url
that seems sufficient for now.
one thing that bothers me about what I've read about Fortran90 is that it is possible in some cases to get undefined behavior when using allocate. So it's like the malloc and free issues of C
could you point me to a good help page for my problem?
i don't know of any good learning c "help" pages. i could point you at some books … http://www.iso-9899.info/wiki/Books
so while malloc and free work well generally when used properly. I still find I'm more productive in a language that has reference counting or GC, especially when dealing with lists.
Also, in callbacks for some code I've found problems with callbacks freeing the underlying data structures that called them, so when the functions unwind (an obvious design problem) faults can occur.
thx twkm!
My solution to that problem was to tag each struct when in a certain state, and then invoke a reaper to process the data structure and release any data at a safe time, after unwinding
Not ideal, but it works and it's fast and reliable. Before that the code was relying on a reference count in the struct, and that wasn't an ideal situation for quality reasons.
considering that arrays can be reshaped using the new Fortran extensions, malloc is rarely required
oh I wasn't aware of that. That sounds better than allocate
read through this when you get time. It's up to date: http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gfortran.pdf
read through this when you get time. It's up to date: a href="http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gfortran.pdf"http://gcc.gnu.org/onlinedocs/gcc-4.2.1/gfortran.pdf/a