11 Oct
By: Jessica
Perhaps I’m missing the right term. I need a way to compress the value down to the size of my hash table, and have that tend not to collide
I think you’re confused
that’s fine, just there are a lot of different kinds of hashtables
Why are you doing this in the first place?
he obviously wants to use a pointer as the key of a table
yes
I am trying to find out non-obvious things by asking him I can make assumptions like that too
The overall plan is to collect reference counts in a hash table and flush them to memory asynchronously. (Checking for 0 happens later, so this is safe.) A previous version used atomic reference counts, but they contend too much for my uses
did you use CAS operations? you can atomically increment an int with two operations in x86 i think
They contend too much. ie, too damn slow
what do you mean contend there is no synchronisation
There is. It’s simply done in hardware
what is your hardware exactly
In this case it’s a dual core laptop and it’s slower with two threads than with one
shouldn’t be that bad i think
any ideas?
certainly it will be faster than using a local table and flushing them out together
sorry, got distracted. I’m having a look now
np
Contended in a tight loop is 8 times slower than uncontended (on my laptop). I want this to scale up to many cores. Using a table will be *much* faster in the long run
you’ll just move the problem to the table flushing code
If I pick a good hash function then each flush will cover hundreds of refcount changes
there’s no way you can have two cpus writing to the same place at the same time, no matter how much extra mechanism you add
maybe thousands
still looking at it. been a while since I did any socket stuff
yea, me too :p
http://dev.ampaste.net/92496 that’s a tricky structure
i need to buy a book wich explain (winApi) how to move files, menage the memory, threads and registry. do you know any good book? for winapi i only find the Programming windows 5 ed (1998), but it seems that explain how to make gui interface, sounds, and something like that. [i studyed from the al kelley - ira pohl 4°ed C ansi] i really appriciate any comment before i ll buy any book xD thanks so much
to move files,
, newfilepathNfilename) –
what does your book say?
erhm…if I had a book…
alright, let me give it a shot hm that works, thanks a lot
np
so I seem to just be missing some cast
then get a good reference. avoid casting, if you think you need one you probably just have bad code.
it was necessary here, twkm
yea, it’s not always unnecessary er
ahh, comes from using the horrid old netdb api.
what’s the alternative?
some day learn getnameinfo … no casts needed.
works on windows and linux?
devicenull, iirc if you look on MSDN MS even recommends it over the deprecated calls
eheh thanks so much sea4ever, in reality i already find something about registry on the msdn, but i was thinking if there was a book that explain all this, because a newbie like me get lost in the msdn library xD
…? Was I actually helpful?
eh..
i didnt know that tip
hmm
What happens if I include a header, that is not needed?
The universe collapses
I’ll need a picture of the number ‘42′ to protect myself then.
hi all. I have a while (1) and I would like to wait something like 0.1 seconds within it… There is a function to do this? Thanks..
sleep(0001) ?
http://graphics8.nytimes.com/packages/audio/technology/20070912threat_final.mp3
wait, hold on, let me get my calculator
usleep
wonderful. Thanks a lot. sea4ever, sleep wait minimum a second.
always good to guess.
so, it can’t go below a second.
Out of curiosity, why do you specifically want to wait 0.1 seconds?
a lot can happen in that time.
xystic_, that was just an example
Fair enough; the reason you were asking then - why did you want a delay (of any magnitude)?
delays are cool! I made an intro movie using nothing but a loop, a delay, and a printf
I did that with a shell script
sleep does wait less than a second
xystic_, good question. I am dealing with sockets for the first time. So, I wrote a simple IRC proxy server and I made a while to recv and send the messages between the client and the server.
sleep(0) hev
since it is non-standard what you say may be true, but on unix-ish systems it is not.
Now it works quite fine. sea4ever, you sad that sleep() can wait less than a second. How?
sleep(150) = less than a second. sleep(1000) = one second.
sleep() on POSIX systems usually deals with seconds, not milliseconds (unlike Sleep() and SleepEx() on Windows)
sleep(0.4)
unsigned int sleep(unsigned int seconds);
so that are integers
hmm, I have not revised math yet, but is -1 counted as an integer?
However, thanks to all. Bye bye.
GoodBye.
yes
sea4ever, but not an unsigned integer.
I think, tonight is the night that I will compile something on linux. somebody tell me how gcc works
no problem, but gcc is more “optimized” according to this.
man gcc
sea4ever, If your project contains more than a few source files, it might be wise to learn how to write Makefile’s If your project will contain many files, or you need to know specific info about the host system, you might want to learn autotools
though snappy is right too, learn the compiler you’ve selected too.
I like Tcc , It’s the only one I can use. just having trouble right now trying to find where it keeps it’s libraries.
sea4ever, Gcc is not hard. What? GCC?
Split personality there Griswold?
gcc -o my_prog main.c something_that_uses_the_math_lib.c -lm ^^ Should work Might have to pass a -Ipath/to/includes
Hold on, let me see.
ok
oh, what does Gcc, use? it complains about stdio.h.
As in, it can’t find it? Oh yeah, you also might want to pass, -O2, -O3, or -Os to gcc
“incompatible implicit declaration of built-in function ‘printf’” - I get this
?
oh, no I did not.
ahh, guessing c.
soon, I will figure this out
sea4ever, Put that include in
I did, but still telling me the same thing
n8
hi
does sscanf pack onto the end of a variable or overwrites it ?
i think the answer to your question is “overwrites it”, but your question wasn’t very clear
idk im trying to use sscanf to read in a path… so i want to keep stacking %s until i reach a final quote character
you’d need to provide an example in order for me to better understand
does anyone know if there is just a plain chat channel? or how i can register for a channel
http://pastie.caboo.se/96679 trying to turn str into the full path within the quotes oops hang on ok go now…
am taking a course on security guy, i am doing some testing and there is something i am not sure http://cpp.sourceforge.net/?show=40340 i am pretty much sure its not C and D i think its B anyone can confirm,debate ?
Evening dudes.
i think either answer is bullshit
Did you know that Linus Torvalds was born 2440583.5 ?
well .. A but this “wrap all” is strange heh
“error: stdlib.h: No such file or directory” and also : “error: /usr/include/stdio.h: No such file or directory” maybe I have them named wrong?
can i have question
usually you don’t use an explicit path with stdio.h, any more than you do with stdlib.h.
when we compare 2 objects to see if they are the same contens, we should define an equals method to see if they have the same variable name? or we define an equals method in the class and use it?
method? class? you probably want ##c++ or ##csharp.
so it’s method class? twkm,
there are neither methods or classes in c.
your question is incorrect. what does ‘equals’ mean?
oh i can’t join java
this conversation is going to end in pain
sorry Spark, you know java?
so, what does equals mean?
compare 2 strings if they’re equal
you mean string comparison? why are you talking about arbitrary objects, then?
he’s clearly in the wrong channel
and does that involve case, dicritcal markings, alternate spellings?
but if you want to tear him apart anyway, you may as well do so
well, he’s not thinking properly. there is no general measurement for equality. except, perhaps, identity. in which case you’re just seeing if it’s the same object in all respects.
there is no general measurement for equality. ” What about ‘ == ‘ ?
== isn’t a general measurement for equality
yeah
what does “hello” == “hello” tell you?
hmm, That there is a serious problem there,
it’s no problem, unless you think that general equality is meaningful.
Apparently it’s for the two things pointing to the same memory location
heyo this may prove fun for some of you http://www.cc.gatech.edu/computing/pads/rcc.html
Someone’s lost their tongue
how did you know?
portuguese or spanish?
not for two things pointing to the same location
The choice of void for return types of reverse functions is less than ideal. heh
good bye!
portuguese
“hello” == “hello”, Tells me at most that I will get an error trying to compile,
quite why they don’t just put it on the website is anyone’s guess
hopefully this is as good a place as any to ask a general programming logic question??
probably
ah, logic, the thing I’ve been told that I lack
I have an increasing array = [1,5,6,7,10,11,12,100] — and x= 9. What’s the best way to return 3 which is array[3] = 7 which is the largest element less than x?
search it.
binary search, even.
start in the middle, then go to the left or right, and keep doing that
or keep dividing in half?
same thing
that sounds like something we did back in cs101 way back when :/ .. but whatever works
it’s a common technique for sorted data
hi, i need to connect two hosts using SSL, just a cert on each end and a TCP connection between them thats encrypted, what would be the best library to use for that? should i use openssl directly? should i use something like curl? does anyone of something else that is really simple?
Yes.
like? zid`,
int m[6][4] I am trying to find the 1-Dimensional offset of the element m[4][2]. The answer is 18, but when I count each element individually, i get 13 or nvm, i think i figured it out
it’s 18 how? :/ I get 33
well if you draw out the entire matrix. you would get 6 rows with 4 columns element [4][2] actually means the 5th row and 3rd column since you count from [0][0]
6*5+3 33 or you can do 6+12 = 18 I suppose
zid`, that would be the 6th row and 3rd column if you draw out the matrix, you can see it
5*6+3 5th column of 6, 3 down
or in other words, it’s Ncols * column element + Row elemenet
I’m not sure which way round [][] goes but it’s either 33 or 18
well, its always Rows, Columns
Hello all question static gint *g_iStuBirth = malloc(sizeof(gint) * NSIZE); that creates a pointer array of of NSIZE * gint right
no.
can I not use that as an array
I think you can or either you can access the allocated memory with *(g_iStuBirth + k)
no. You might pretend it is one for some operations, though.
It allocates enough memory to store sizeof(gint) * NSIZE and returns the pointer you can use [] to index it if you wish
ya thats what I thought but the space is reserved on the heap
no, that’s an array
there is no heap in C.
zid`, so would you access the “array” by g_iStuBirth[x]?
I suggest calling that a vector to avoid confusion with array types.
it’s not an array arrays are on the stack
no but it’s 30 pointers right
there is no stack in C.
you are mistaken. char (*p)[5] = malloc(sizeof (char[5]));
spec says it’s not an array
what do you think *p is? I’m talking about your nonsense about arrays being ‘on the stack’
oh lol
howver, the spec does say that it is an array.
I may or may not have made that bit up
what it doesn’t say is that it is of an array type.
no, it spec says nothing of the sort
please stop making up nonsense. read the spec
that makes more sense
okay back to my question
aww
so I can use my statement as an array right
I’m having fun playing with Zhivago
docmur, no.
if you’re stupid, yes. I suggest that you don’t use that, so that you can use array as referring to the array type. types, even. also, pointers aren’t arrays in any case.
okay I know there not “int *iArray” then use *(iArray + 1) to referance them
well, that’s fine — just don’t call iArray an array, because it isn’t.
do it then?
arrays can be thought of as pointers to the first element in the array
arrays are pointers
kawfee, that is incorrect.
nope what is the word I am looking for
kawfee, char *a. What type is &a?
in c++ i know arrays are not pointers, so i would assume the same for C
Draconx that is not an array
kawfee, I am well aware it is not an array.
arrays turn into pointers at some point
arrays are not pointers, nor can they be thought of as pointers to their first element. an array _evaluates_ to a pointer to its first element.
you show me an array and I show you a pointer
no, you won’t.
prove me wrong
it would be useful to think they are pointers to the first element
it’s all in the standard.
sure it is
kawfee, char *a. What type is &a?
only if you think that it’s useful to be wrong.
I am just saying arrays turn into pointers at some point
char a[10]; what is sizeof a?
so? newton’s laws of motions are also wrong but they are still useful
the value of something is not that something. this is the critical error that you are making.
I am looking for a word. Maybe it is dereference I don’t think that is it
no, it is _evaluate_.
degrade maybe starts with a d I am pretty sure
can’t answer the question? why not think of it like a pointer?
degenerate?
nope close
read the spec sometime.
it’s what happens to arrays to become a pointer
what do you mean?
it’s called _evaluation_.
what question
that’s not it
char a[10]; what is sizeof a? you are mistaken.
I might very well be but when I look at the ASM I see a pointer degredate maybe (sp)
C doesn’t have ASM to look at.
what is it? i do not have gcc on this machine is it 4 bytes?
anyways, I wont argue
you are thinking of ‘decay,’ and it’s a word made up by idiots who don’t read the spec or think about it. wrong.
char a[10]; what is sizeof a? what is the answer to that?
that’s it! decay
lol
when you run a C program through a compiler which outputs, say, x86 assembly - the result is no longer C and you cannot make statements about C from it.
if you know c, then you can answer the question — it doesn’t matter what machine you have.
I didn’t make up the word decay. I found it in the dictionary.
sizeof a always has one value for this example in C.
don’t some funny g99 allow asm?
Zhivago, didn’t you used to say arrays would decay into pointers?
you mean inline asm? mairi he read the spec
I have not always been as wise as I am now.
lol
heh
can’t answer it?
aahhahahaha
Zhivago wisdom comes with age
gotcha!!
not really
no, that’s senility.
i not have gcc and i do not know C
Zhivago don’t be so mean to those who call arrays pointer when you did at one point. =|
so i cannot try it and see
shit, I wont get senile in my old age I’ll be dating an 18 year old of course.
you’ll get alzheimer’s disease
well, then stop making stupid claims.
maybe, but then I wouldn’t even know to care
you might want to look up what senile means. no, I never called arrays pointers. I once confused evaluation with decay, which is quite different.
you said decay oh I see what you mean haha look at the ASM for an array then Maybe I am getting senile.
What is decaying, then?
there is no asm for an array. a fairy tale made up by the unlearned.
the hell there isn’t
find it in the spec.
what spec? ASm doesn’t have a spec
so, you agree that your claim is meaningless in C?
quite possibly yes, now that I understand what you mean by evaluate. And when you say evaluate you are talking about the compiler?
no.
hrm ok explain?
what does 3 + 4 evaluate to?
3, +, and 4 in an expression tree which ends up being 7
what is the answer though?
I bet this is a trick question
there is no expression tree in C. 10.
is it just the length of the array * num of bytes for the elements?
Zhivago there is in the compiler
int a = 4; what does a evaluate to? yes …
kawfee, we are talking about C, not a particular compiler.
char *p; what is sizeof p?
Zhivago not sure what you mean by evaluate there. that is just assignment
there is no assignment in my example.
I get your point though
then answer the question.
a = 4 is assignment you declare and assign it
s/asign/initialize
int a = 4; is initialization. so, what does a evaluate to?
when you initialize it you assign it forget it
no you don’t — consider const int a = 4;
you are thinking in C too much
well, I didn’t expect you to be able to think rationally.
why not? How about logically?
that either. go and find out what ‘evaluation’ means.
You have constricted your mind. C exists on top of ASM
wrong.
I know what evaluate means. right.
so, what does a evaluate to?
I don’t think it does. It is just a number. stored in some register somewhere What are you trying to prove?
then you don’t know what evaluate means.
I suppose I don’t know what evaluate means in Zhivago’s world. It’s 4. that’s it
well done …
you pass it as a parameter and it is evaluated it is 4 always I love lazy evaluation btw
the same process is what produces a pointer from an array.
which C sucks at
no, C just doesn’t do it.
yeah I know =] would be nice if it did
I think it would make side-effects much harder to predict.
I hate side effects too those should be abolished
then C would no-longer be procedural. you would end up with a functional language with a horrible syntax.
probably not exactly!
hey
haskeel ftw haskell ftw
well, I guess haskell has a horrible syntax.
does not don’t spread your propoganda
say I Want to get the time and store it in a variable, then see how long has elapsed since the current time, how can I do that?
endra two vars time on each then sub
endra, using time_t, time() and difftime().
What I need really is just a way of getting the time, and what var to use
or that
thanks
he said time_t
not “or that”; subtracting the results of two calls to time() does not necessarily yield a meaningful result.
clock() might be more precise than time()
well I didn’t know what he wanted
clock may also do something completely different. since clock is defined to tell you approximate cpu time used — not real-time. you may also wish to investigate gettimeofday()
clock_gettime(CLOCK_MONOTONIC, &ts); is better than clock() if you want non-virtual time. but a lot of systems lack support for it. gettimeofday is nice until ntp updates the system time
I’d just count on my fingers if i ran out of fingers the answer is “lots”
zid`, when i run out of fingers from counting to 10 I have to punch you. 1..
11!
it’s not about what he wants — subtracting time_t’s is incorrect in C.
difftime is fun
so is anal
right
kawfee, why are you here? I think Teckla ran away to here to get away from you
he hasn’t said anything to me here. I’ve been here for years anyways do I have to go in hiding?
well i told him to put you on ignore. so maybe the problem is solved
did he really? =[
teckla is a big mouse.
I’m a pussy cat
disgusting chats
well, he chose the name.
night everybody, an out-of-topic question: are there anybody in the channel, who have worked in the design of a processor, and give me approximate times of design phases?
I ran out of fingers again!
i’ve designed a processor in a school course or, it was microcontroller i guess, or whatever you call it
hurrah.
vlii, thanks, but i need a real high performance processor
intel didn’t hire me instantly
does that mean that they eventually hired you?
no, hasn’t happened yet :/
fpga?
haven’t dealt with such
CardA[k].name = (char *)malloc(strlen(tmp_name)*sizeof(char)); say I allocated space for that “element” in my struct and I want to assign a value of 25 to it. do I use *CardA[k].name = 6; or just CardA[k].name
what do you mean by a value of 25? int i = 25; ? or “25″? or what?
i want to assign CardA[0].name to be 25
and what type is CardA[0].name?
char *
why would you want to assign an integer to a char *?
Frasha, for example…
what does 25 mean as a char *?
CardA[0].name type is the type defined for the member name
how long is that example that you’re taking 4 minutes to type it up?
Frasha, I spent the last 4 minutes to figure out my question. thanks for the effort anyways
maybe it would help if you said what you wanted to accomplish
Joule/sec/Amp
Frasha, I’m just not a very effective communicator in C terms. It’s hard for me to explain what I want to do in this channel, though I am learning to get better at it
well, that’s a surprisingly realistic appraisal. char *p = 25; - what does this mean?
it assings the value 25 to the variable pointed by p?
Me thinks it makes a pointer pointing to a character at address 25
no, for starters, it’s an error because p and 25 are incompatibly typed
zid`, yea i agree
if it were cast, char *p = ( char * ) 25; then it would assign the address 25 to p, but it would still be wrong unless you know what’s there
the ROM header, on dmg
i see
probably the nintendo logo image
so, why would you want to do that? actually, it would assign an implementation specified address.
partially anyway, since you’d have supplied the 25 which would be translated to that implementation specific address
partially what?
I guess what I really wanted to do was to assign teh value of 25 to the variable pointed by p?
the implementation is allowed to produce a random address given 25 if it likes.
it would be partially implementation specific, since the implementation would have nothing to go on if you hadn’t supplied the 25
you should allocate some memory then imo
what the hell does “the value of 25″ mean here? so you mean you want *p = 25?
yes
do you mean 25 translated to a string? something like sprintf( str, “%d”, 25 ); ?
then you’d better point p somewhere sensible. why is p a pointer?
because you declared char *p; ?
why … did … you … declare … it … as … a … char *?
to get to the other side! wait, wrong punchline?
so that I can store the address of a string to it
if you want to store a string to it, why are you also trying to store 25 into it?
I was just trying to come up with a simple example… I didn’t realize that it would be SO WRONG
stupid examples won’t help you.
they might if you’re even stupider than the example
mmmm, no.
an example of what?
(noob question), any mac c developers hanging around here.
taking polls ftw!
I’m trying to get the size of a file using sys/stat.h the old method st_size returned an int, this doesn’t seem to be the case anymore
size of a file? I just use the hack way fseek(f, 0, SEEK_END); size = ftell(f); rewind(f);
I have to write a du program
wee for undefined behavior
doesn’t work.
I’ve never had it not work
I can’t help that.
the st_size is now off_t
so your definition of doesn’t work isn’t entirely accurate
open the file in text mode or binary mode. no, it’s entirely accurate if you read the spec.
zid`: sorry
shouldn’t work you mean?
seeking to SEEK_END isn’t defined to work for binary files.
cus acctualy, it DOES work
seeking to the nth position isn’t defined to work for text files. accidents will happen …
there’s a big figgerence between does and should
please learn how to spell “because”, zid’
and a big difference Are you mocking my dialect?
please stop spreading misinformation.
yes
please learn to spell colour
now, explain to me why that approach is clearly wrong for text files.
\r\n vs \n last I checked that really fooks it up
i’ve always wondered why they chose that behavior for fseek()
then you have half of it. what else would you have it do?
i understand it for text files, sure, but for binary files it doesn’t make sense
binary files may be padded (generally with null bytes) it’s necessary for systems which only support files made of blocks. if you want to know the number of bytes in a file, I suggest that you use fstat() or some other system dependent mechanism.
what about that prevents accurately seeking from the end?
yo know I mentioned it was a hack right?
uh, when your file must be a whole number of blocks long … and you only wrote a partial number of blocks …
and so the system doesn’t store a real length?
I never said that’s the proper way to do it, he just said he couldn’t get stat to work, so I suggested a hack that might
not all do. well, just flag it as working by accident in the future.
how would you read a file like that back in without already knowing the size then?
you may know the number of blocks in it …
but not the specific number of bytes?
or you may have written down the length somewhere.
so does fopen(…, “a”); work for binary files?
that must suck if you have 4kb blocks
well, you can write down the number of bytes somewhere if you like. somewhat — but think about tape-drives.
I want my floppy back floppy back floppy back
yes, assuming that you’re happy to write after a bunch of padding. we’re talking about the EOF mechanism for the device here.
it’s no wonder you hate c so much, with the standards committee bowing down to the lowest common denominator
Zhivago, okay. I’ll take that as “no, not like you might assume it would”.
you can imagine a flag on a block specifying that this is the last block of a file. actually, I tend to think it’s reasonably sensible behaviour.
could someone tell me why this doesn’t return asdf in both variables? sscanf(”asdf:asdf”, “%s:%s”,&t,&s);
don’t use & with strings
try %[^:] instead
%s reads whitespace delimited strings
ok… so (”asdf : asdf “, “%s:%s”,&t,&s); should work?
test it
well, I am asking because I think i did and it did not but I can test exactly like this well, yes… returns asdf in the 1st var, nothing in the 2nd
that’s because your format didn’t have spaces around :.
huh
try sscanf( “asdf:asdf”, “%[^:]:%s”, s, t );
so the I need spaces, because %s is space delimited, but I cannot have spaces, if they are not in the format string? so the format string using %s needs to have spaces in every case, else it will not work?
format needs to match exactly (except that whitespace gets glossed over). if you don’t use %[ then the first %s tries to match the whole string up to the first whitespace. scanf does not backtrack to find the best match.
I actually wanted to match something like “discard-this [asdf sadf]:[asdf asdf]” - I guess “[%[^]]]:[%[^]]],&a,&b” should do that? trying
if a and b are char *’s then taking their address like that will be an error, don’t do it
can I match “end of string” like in perl? e.g. by including so what should I use instead of &a?
what type do %s and %[] expect?
I thought sscanf needs the pointers to a variable
just use a
sscanf needs pointers to places to write things …
with strings it expects the address of the first character position to be written to
scanf needs pointers, it doesn’t need &.
& will convert a variable into its pointer?
no, &x means ‘a pointer to x’ int a; what type is &a?
thats what I meant pointer, pointing to the position of a
types don’t point.
what type is &a? if I wrote p = &a; what would you need to declare p as for that to be correct?
“int *p;”?
and what type is p?
hm
Zhivago, me!
ehe sounds like int
sounds like a fart
somebody needs a book.
int x; what type is x?
integer
yes, do you have a C book? integer is not a C type.
what is, then int?
amazing.
well, that’s a short for integer, I thought
if int x; defines x as an int, then what would int *x; do? int is a C type, integer is not.
define *x as an int…
int *x makes unary multiplication
do you have a C book?
yeah
an address space which can hold the location of an actual int
read it until you can answer my question.
btw, when did amnesiac start to troll?
just right now, calm down
awe shucks. I’m recovering from the terrific Zesty/Spicey Chili I made tonight.
uhm.. habanero sauce == yay!
chili zest doesn’t sound too good.
I used that new Hunts sause they call Zesty/Spicey. Not bad.
I don’t think that chili has zest.
Mustrooms/bag of frozen veggies, it’s really quite good
Mexican sauces == great
I think I read quite a bit on variables a bit of a longer while ago…
well, then answer my question.
but if you get into things like calling integer wrong for int… well…
type integer int; typedef integer int; (sorry)
you should be sorry, since it’s still wrong
there are many integer types in C. there is one int type.
well… still int is an integer
if you can’t handle a little precision, then you may wish to go back to wallowing in perl. so what? I asked what C type it is.
“wrong” is not a 100% correct well, maybe
yes, it is 100% wrong to say that something is of type integer in C.
if you say so…
char c; - what type is c?
unless you do typedef int integer;
char…
why didn’t you say integer?
of course, you could really define it as something that’s not a real integer type, that’d be funny
isn’t that pretty typical?
typedef int int24; //for example
because I’m such a damn quick learner…
typedef char * BigInteger;
i’ve never seen a bignums implementation that didn’t wrap the representation of the number in a struct, but i suppose you could do it that way typedef float integer;
ah a struct is still not an integer
typedef float bytearray[8]; //what about this?
yeah, but it’s not as funny then
typedef float char bytearray[8]; //what about this?
you enjoy code obfuscation, don’t you
probably should have said unsigned char
yes, i especially like deciphering obfuscated code
typedef isn’t something I use everyday.
good so, int *r; what type is r? what makes an integer an integer?
pointer to an int?
ok.
i worked on a C project for a while that was implemented almost entirely without comments, because the programmer thought it was more elegant that way. he also believed in minimal typing. that was fun!
so “pointer” is a valid c type?
what does scanf expect for a %s argument? no, but “pointer to int” is you should write it as “int *” in the future.
I was waiting for more word-games, actually… that made answering a bit hard previously
You’re doing fine.
no games — just correcting your broken thinking.
seems more like tightening up his loose thinking really
now throw in the part where C doesn’t know what an integer is
I would call it a string… but that’s probably not satifying you
it’s hard to imagine someone would think that’s a good way of doing a project, i wonder is it public? sure obfuscation may be fun, but it should be kept a hobby, not to be used for real work
so if it’s at the end of the line, I could do sscanf(”xxx [asdf a]:[asdf s]\n”, “%[^[][%[^]]]:[%[^]]]”,m,t,s);
why do you want to use sscanf, btw?
what else should I use?
what problem are you trying to solve?
I have a string, I want to extract data from it seems to be the right guy for the job
post your code so far: http://rafb.net/paste/
it’s just that line with a variable instead of the string
please see if you can describe what you want to do more intelligently.
in a game, i get a string in the form of message [pl1]:[pl2]
how can i use a pointer to a 285×2? it keeps telling me “error C2109: subscript requires array or pointer type”
I want message, pl1 and pl2
285×2 array of ints^^
int a[285][2]; or int a[2][285]; ?
[285][2]
and you want to get at a[x][y]?
i’m passing a pointer.. &array[0][0]
that will be of type int (*)[285][2]
that’ll just be an int *
and i’m trying to use it in a loop array[i][0] right
ya it builds fine if we leve off the [x][y] but soon as we stick em back on it complanes the array is not a array
i’m using an int*
personally, I would use strspn and strcspn
im with mean
i’m using int*
ok, well, what’s the problem?
and passing it &array[0][0] and when i try using it else where
Zhivago, ok, I will look those up - but I think the one I have will do so thanks everybody
the compiler gives me the error i pasted above subscript requires array or pointer type
well, you can’t use 2 subscripts when you do that, either declare the function to take an int[285][2] and just pass a, or make it single dimensional
so i can only pass a single row of the array?
so you cant pass multidemintional arrays then?
you can pass them, but you must declare the function to take them
oooo
what do you mean?
it’s pretty late here, time for sinking in the arms of morpheus (if that’s how it’s said in english)
and don’t take the address of the zero’th element like that
i see what hes saying
thanks again and nite
so do function(int[285][2])? then i’d be passing the whole structure .
its like my triple pointer int*** smap; if ya want a 3 way array *** if ya want 2 way ** if you want 1 way *
yes, and just pass a without &[0][0] crap
learn about pointers to structures
no, you won’t be passing the whole structure
meanmon13, you can’t pass arrays in C, only pointers to them.
thats waht wer doing passing only a pointer
you’re passing an address, so if you modify that array in that function the changes will be reflected consider a simple example, void foo ( int a[32] ); could be passed an int * or an int[64]
64?
i could’ve said [1234], it doesn’t matter
I’m sure the compiler will complain about incompatible types.
so it’d work the same for a two dimensional array
yes, just make sure to pass another two dimensional array to it
the second dimension must be present when accepting 2d arrays
i suggest using both when declaring and defining the function, not just one
so i don’t have to include the pointer symbol 0.o
since you’re using a 2D array and not an array of pointers, you can’t
k
sure you can
and if you mean address of operator, you shouldn’t
just hope i’m not passing the entire structure .
void foo(int (*p)[2])
you won’t be and it’s not actually a structure
it is, but it’s not a struct.
well i just don’t want to be passing around that much actual data
stop worrying, you can’t.
error C3409: empty attribute block is not allowed using int[285][2] array type
are you giving it a name?
yes func(int[285][2] array_name)
C is not java.
wrong placement, between the int and first [ is where it goes
so i need func(int array_name[285][2])
yes
where can i find documentation that says its not making a copy of the data passing it without *?
in your C book.
you could get a copy of the c standard
mean we can just look at the asm output
the value of an array is a pointer to its first element. there is no asm output.
yes there is
0.o
if its enabled
no asm output lol
looking at asm output would not tell you anything about how C works.
c and c++ compile to asm if enabled it wont delete the asm output and yes it will
c and C++ compile to whatever the hell the compiler wants to compile to.
as i speak rather fulent asm
so what?
i has to compile to asm… processor only speaks asm
that will tell you what one particular compiler is doing — think about it.
c and c++ compiles to asm and then the linker converts that to binary
wrong. c and c++ compile to whatever the compiler compiles to. this isn’t necessarily asm.
ya that will be your little secret
meanmon13, processor speaks machine language. asm is not machine language.
the processor does not understand anything other this asm.. i uses asm opcodes asm is machine language because each command in asm has an opcode
the processor does not understand asm. each instruction in asm generally has a whole bunch of opcodes.
meanmon13, that’s like saying english is french because it has words that mean the same.
not really, label db 0 doesn’t have an opcode
zhivago your processor only understands hex opcodes witch are asm when someone sayes asm thay genarly mean the more readable text version but pepole like me can read the hex version witch is still asm
I though processors understood binary, not hex. thought even.
well its binary
each instruction may have multiple bytes, but generally only one opcode
binary hex
…
its all how you read it
haha.
binary and hex are numbering systems
“binary hex”.
11 = 3 in hex
oh, the confusion.
you see 3 processor sees 11 doesn’t matter
generally a given instruction selects between a bunch of opcodes.
its all the same data i say aa you say 10101010
you aren’t fluent in asm.
you have yet to read my asm ok lets just add ignore zhivago
consider mov %eax, [10] etc — that’s selecting between a while bunch of mov opcodes depending on the arguments.
…
let’s not announce ignores.
that would be overloading, it’s not as though the instruction is generating more than one opcode at a time
well, that’s what selection is about.
There’s an assembly based OS out there. Licensed under the GPL.
menuet?
When asked for the code, people joked, “The code is in the debug/assembly output!” Frasha, yeah, that’s it. Ahh, the license seems to have changed. Maybe that wasn’t it. Whatever. http://sourceforge.net/projects/menuetos
hmm, why is it interesting that it is written in asm?
I thought the interesting part was that joke when no one could find the GPL’d source code.
it’d be more interesting if it was written in basic
FreeBASIC is capable.
I’m looking forward to javascript taking over.
I wrote an encryptor/decryptor in Javascript. It was weird how it ‘knew’ what the datatypes were supposed to be.
javascript could be a lot worse but I’d rather compile to it rather than write it by hand.
why compile to it?
http://www.newmars.com/josh/rot-pi.html heh still on my website (sorry for the OT)
well, it’s a toss up between javascript and .net well, ecmascript, I guess.
but why compile to either?
and I suspect that ecma will win. because, I suspect that the browser will end up running most of our desktop applications
i sure hope not, i can barely stand to use a full-featured browser to check e-mail, let alone to run any sort of real application
There’s your browser based desktop/OS.
why is that?
because i have a crappy computer, mostly
well, that’s ok — it will die reasonably soon.
are you trying to jinx me?
also, you’re probably not using a browser with a high performance ecmascript system. I’m fairly happy with gmail performance on a crappy machine.
I run gmail in compatiblity mode. The load time in regular mode is horrendous. It needs to load a meg or two.
well, that’s why you need caching and so on. but the potential is pretty much there already — just wait a couple of years, and I suspect you’ll see a lot of desktop applications migrating to the browser.
OK I lied, just checked and it’s 600k, still a bit but yeah. Takes a few seconds to load.
I run it in full mode without noticing, but we have broadband.
Same here, but it still takes a second.
I’m exaggerating that pithy 3 seconds, but I like instant loads for most things. ie, blink of an eye.
Once it’s loaded of course moving around is fast.
You developing that sort of web based thing Zhivago?
isn’t everyone?
Not me… not web browser stuff.
I suppose it only really comes into play where a user interface is involved.
I am going to be doing networking stuff soon. For my own little hobby project.
no, I don’t do UI but it’s of interest to me for distributed systems.
silly question. Does a boolean value actually consume 1 bit of memory, or is more memory allocated and wasted for it?
it all depends on how you define it and store it
this is avr-gcc by the way… for an avr microcontroller boolean [] { 1, 0, 1, 0 }; ere boolean val[] = {1, 0, 1, 0};
C has no bool join #pascal for boolean
_Bool how have you defined boolean?
ok, good to know
Frasha, in c99 ..
c99 is still c
I’m using a library, so it must be defined in here somewhere thanks
I refused to acknowledge c99. c89 for ever ^_^;
how exciting for you.
you have a strange definition of exciting
#define boolean(x) ((uint8_t)((x)==0?0:1))
that’s not a type
oh yeah, a macro drat typedef uint8_t boolean;
well, there you have it then, as much space as a uint8_t takes up, that’s how much each boolean would use
so it’s really an unsigned 8 bit int?
though, hopefully that macro isn’t used in the same place as that type if uint8_t is that, then yes
the typedef and the macro are defined in the same file but, I didn’t write any of this it’s the source code for arduino (www.arduino.cc)
personally, i’d give them different names, but to each his own
thanks for the tips guyg guys
can someone recommend a ml/forum where i could ask about concurrency and threading solutions for specific programming cases?
hello? 492 nicks, no one chatting?
try devshed, i’ve wanted to find a c list for a long time, the only good one seems to be on usenet
shall we entertain you?
c is not for Chat it means Cool
thanks
I suggest ‘counterproductive’
cboard.cprogramming.com isn’t too bad a C web forum
You should start a good competitor.
why? I mean, why would you want to compete with C?
I think it would be a good and interesting project. I meant a competitor to cboard.cprogramming.com
I know this is really more of a *n*x question, but… what happens if I free() a pthread_t from inside the thread?
Not to the C programming language.
undefined behaviour, I expect. that sounds like effort.
freeing any object then referring to that object is undefined behaviour.
‘k
Hmm… any suggestions for how to dynamically allocate memory for an arbitrary number of pthread_t items created at various times, and keep track of them to free the memory as each thread returns?
Of course, it’s a whole lot simpler to just malloc() away and ignore the minor issue of the memory leak
why are you mallocing memory for a pthread_t?
Because I don’t know how to do it The Right Way
why not find out? what are you doing with the memory that you malloc for a pthread_t?
Putting a pthread_t in it
why?
It’s gotta go somewhere, right?
no
Ah
that’s just used to tell you what thread was created
Can I just use one, and keep overwriting it as I create the new threads?
you can just use a local variable if you don’t care about the pthread_t, then sure — reuse it
i’d use a linked list to keep track of active threads, if one thread wants to close, change a node property and make the main thread free the memory
why?
multiple concurrent threads?
what problem do you think this would solve?
Sorry for asking an off-topic question, but is there any way to dynamically allocate memory within a debugger? GDB, for ex.,
call malloc
I want to resize a memory location realloc is not working
then do it “ is not working” is not an intelligent description — please try again.
So, it is possible? That means, I am doing something wrong. Let me check again.
do you understand how realloc works?
Yep
so, how does it work?
Thanks for the clarification, Zhivago
welcome.
The problem as I understand is not because of how realloc works, but because of some symbols problem
and what gives you that impression?
*my understanding of how realloc works The message that I am getting? It says unable to find that symbol. Obviously, I might have been using a release version of that library, I guess.
does your program call realloc? otherwise, just use malloc and memcpy
From with in the debugger?
… yes …
OK, Thanks. I will try to do that, and tell you. The problem is somewhat different, but I had to simplify it a bit… Anyway, I am working on it.
you have been quite poor at explaining your problem so far, so it doesn’t surprise me.
is there a channel for secure coding?
what does that mean? use strncpy, strncat, snprintf
heh
Join http://www.learning-c.org - Forum and chat, just opened!
your forum sucks. it has zero users and zero posts.
Hey! It opened 10 minutes ago!
I don’t know what you might achieve by posting it here, except annoying some people.
Jeez… It is just an initiative…
you could have picked a nicer language. infact. it’s not too late to delete your forum and pick one now.
jeffz, yeah because ##c allows non-english speakers a place to talk about C.
I don’t know of any rule - but I have seen it happen before.
hiya there
jeffz, uh huh
anyway, - I think the more important issue is the choice of language :p
hey
hello
say I had char skill[2] and I wanted the value to be 0, do I do skill[0] = ‘0′; ?
you wanted both values to be zero? (skill[0] and skill[1])
yes
on initializing?
Yes
char skill[2] = ‘0′;
char skill[2] = { ‘0′, ‘0′ }; no?
yes sorry, my bad
I don’t even know why I’m using char
thanks
… find out why you’re using char btw, if that character were printed as an integer, it would not be 0 it would be 40-something i think (the numerical value of ‘0′) if you want the NUMBER 0, then you either want ” or just 0 ” == 0 (the null character)
its nice having so many zero’s to choose from
but ‘0′ == 48 in ASCII
but not in C. fortunately in C, ‘1′ == ‘0′ + 1
can you programmatcally set the theme on a per app basis with gtk? sorry to ask here but #gtk is dead
i know, i tried talking in there once
heh
and you’ll not get an answer here, either
oh
because i’d wager most people here don’t know GTK me included
Well you see the reason I’m using char is because it is user input, but once I got it in the char I need to convert to the int, and I wanted to set default to ‘0′ in case he didn’t give input for the char
why do people do GUI programming in C anyway?
because they’re insane
heh, i’m using lisp i was just looking for a gtk guru
from what i see of GTK, it’s twisting C horribly
that’s necessary, because C is horrible
So say my char[2] is ‘12′, then I need to get that in an integer.. what would be the best way to do so?
for the same reason that they program in C in general I suspect congenital insanity.
GUI programming or just GFX output? ie, I do some minor graphical output using SDL, but that’s about one app in 100
probably use atoi
yes, perhaps
thank you
have you considered strtol?
man pages say that for ‘long int’ int foobar;
iirc, it doesn’t matter, though see if the compiler complains about it i can’t really remember tbh
of course it matters
So should I use atoi?
or use a long int instead of int
thank you Cheiron hrm chrisjw: god damn it Chris
you’re welcome
in my atoi, the man page defines it as int atoi(blah) not long int
strtol returns a long strtol is better than atoi because it supports multiple bases and detects errors
ah right i was just gonna say write a function that uses atoi sorry, i missed the part where you recommend strtol i thought he was talking about atoi
I didn’t, Zhivago did
there you go teaches me for not even attempting to read
char skill[2]; int skill_int; skill_int = atoi(&skill); src/game/g_admin.c:1866: type error in argument 1 to `atoi’; found `pointer to array 2 of char’ expected `pointer to const char’ How can I fix this?
well, pass a pointer to char instead of a pointer to array 2 of char.
How is &skill a pointer to array 2 of the char?
because skill is an array 2 of char so clearly, &skill will be a pointer to an array 2 of char
So, it should be &skill[0] ?
yes, or better, skill
i like &skill[0]
But it says that it needs to be a pointer
more obfuscated
arrays in value context are the pointer to first element.
an array is a pointer to it’s first element
in value context
Ah! Thank you
right
doesn’t atoi expect a null-terminated string?
it sure does
so that’s not quite gonna cut the mustard
depends on what the array contains, i guess
for 2 elements, seems easier just to do the conversion yourself
definitely
skill_int = 10 * (skill[0] - ‘0′) + skill[1] - ‘0′;? that is, if it’s not null terminated
aye
I have one more question
doesn’t want to work
(arr[element]).member?
struct_name *temp; temp = &array[4]; temp-foobar
are you doing myfoo[4]-bar?
array[4]-foobar
yeah, you want myfoo[4].bar
struct foo x[10]; x[2].y = 4;
array[4] is of type struct, not struct *
sorry thank you
Im learing how to open a file and read it using fopen .. got that too work but now I want to send the file to another function .. how would I do that?
you don’t “send files” to functions, but you can pass the FILE * to it. ie. FILE *p; p = fopen(…); some_func(p);
k thanks wasnt sure if that was the case ..
You can also pass a char * to a function with the filename, call fopen within the function, and return a FILE *
naturally
if you’re doing repetitive initialization or something
Im learning so open to suggestion ..
sounds like you’re doing ok
well gonna try this out and see if it works ..:p
does anyone know a howto for ncurses to create a window scroll bar?
What method should I call if I want my mainthread to sleep 100ms?
usleep
istabuinusleep
shut up mprentice
not likely
bbbrrr
Personal phpnuke web hosting solution!
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Feb | ||||||
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
Leave a reply
You must be logged in to post a comment.