RE: Calling sequence
Yeah, I asked a few professors here at school about it and they said that it's a fundamentaly undefined statement. Also, I've been meaning to ask you what the perl script at the bottom of your emails does. I beleive statements with multiple side effects are undefined in ISO C standard and that is why everyone is getting all sorts of weird answers, but I may be wrong. I like this answer. It means there is no correct answer, and I can stop scratching my head on what is the proper answer. :-) Like I said from the beginning (or maybe I just thought it, I can't remember), the example line is bad programming so it shouldn't be done, anyway. ~Patrick
RE: Calling sequence
On Thu, 29 Apr 1999, Mullen, Patrick wrote: # Like I said from the beginning (or maybe I just thought it, # I can't remember), the example line is bad programming # so it shouldn't be done, anyway. yeah because if you miss out the spaces it becomes i+j (or whatever the variables were) and looks a right mess. -- +++ The program isn't debugged until the last user is dead. +++ [EMAIL PROTECTED] http://www.penguinpowered.com/~a_out
Re: Allocation
On Wed, 28 Apr 1999, Amol Mohite wrote: in main function if i have int i, j; can i be sure that i and j are contiguous ? Not at all. You can put them in a struct, or make an integer array if you want contiguity. Brandon
Re: Calling sequence
Amol Mohite wrote: In gcc, if i = 2; then j = i++ + ++i; what is the value of j. i++ == 2 ++i == 3 = j == 5 what is the calling sequence in this case ? ++i first or i++ first ? ++i; i++ will increment i after the expression has been evaluated. why does fork have to return a value of zero to the child process ? Because it does. fork() has to indicate whether the processes is the parent or the child. It also has to return the child's pid to the parent (there isn't any other way for the parent to obtain this information). The child can just use getppid() to find the pid of its parent. why not -5 or -6 ? What would a negative return value signify? (currently a negative result signifies an error, which is the standard convention for functions which normally return a nonnegative integer when successful). -- Glynn Clements [EMAIL PROTECTED]
Re: Allocation
On Wed, 28 Apr 1999, Amol Mohite wrote: # in main function if i have int i, j; # # can i be sure that i and j are contiguous ? does it matter? (think about it, what use would knowing if they were do you?) they could be, then again could not be. Does it depend on processor archetecture and operating system? -- +++ The program isn't debugged until the last user is dead. +++ [EMAIL PROTECTED] http://www.penguinpowered.com/~a_out
Re: Calling sequence
On Wed, 28 Apr 1999, Amol Mohite wrote: oh goodie, more homework to do :) # In gcc, # # if i = 2; # then j = i++ + ++i; # # what is the value of j. 6. # what is the calling sequence in this case ? ++i first or i++ first ? it'd do this: i = 2 i++ /* add 1 to i and return 2 */ i = 3 ++i /* add 1 to i and return 4 */ add 2 and 4 and give you 6. # # why does fork have to return a value of zero to the child process ? if you have to ask this then you've never written a program that uses fork() and understood it. # why not -5 or -6 ? because in the switch statement you wouldn't know if you were in a parent or child. let me know what grade you got for that homework :) -- +++ The program isn't debugged until the last user is dead. +++ [EMAIL PROTECTED] http://www.penguinpowered.com/~a_out
Re: recv
On Wed, 28 Apr 1999, Glynn Clements wrote: # # Why don't you just use fgets(), fscanf() etc? # how? don't they need a FILE pointer not a file descriptor. (this is probably # a very silly question with a very simple answer...) # See the fdopen(3) manpage. Ahhh... i see. FILE *foo; foo = fdopen (sd, "r"); /* where sd is a socket descriptor from socket() */ What's the maximum size of data you can send over a SOCK_STREAM in one go? -- +++ The program isn't debugged until the last user is dead. +++ [EMAIL PROTECTED] http://www.penguinpowered.com/~a_out
Re: Calling sequence
On Wed, 28 Apr 1999, Glynn Clements wrote: # In gcc, # # if i = 2; # then j = i++ + ++i; # # what is the value of j. # # i++ == 2 # ++i == 3 # =j == 5 no. it's not. I typed this in: main() { int i = 2; printf ("%d", i++ + ++i);} and when i ran it i got 6 printed... -- +++ The program isn't debugged until the last user is dead. +++ [EMAIL PROTECTED] http://www.penguinpowered.com/~a_out
Re: Calling sequence
On Wed, 28 Apr 1999, Amol Mohite wrote: secodnly in fork, -1 rmeans an error no -ve value. so wo my qs. again, why 0 ? First off we need to know if our fork was successful so we return a -1 if it was not. Then we need to know the pid of the child if we are the parent, so, why not make that the return value of the fork. We know all pids are positive integers so any value greater than 0 could be a pid and as such you have to treat this entire return range as indication that you are the parent. Then, allw e are left with is how to tell if we are the child. If you'll notice from above, -1 and 0 are already taken so why not just use 0. Of course we could use -234 instead of 0 but that would not be very intuitive and C and UNIX are the two most intuitive enviroments every and we would not want to break that:) If my rambling sound exactly as such look at this code and see if that helps. if((child_pid=fork())0){ /* check for an error */ perror("fork"); exit(0); }else if(child_pid==0){ /* here we are executing child code */ child(AcceptS); }else{ AcceptS.Close(); waitpid(-1,child_status,WNOHANG); /* here we are executing parent code were we may need to no the pid */ } ... [EMAIL PROTECTED] `:::' Kevin Sivits ... .. ::: * `::.::' ::: .:: .:.::. .:: .:: `::. :' ::: :: :: :: :: :::::. ::: .::. .:: ::. `. .:' ::. ..:::.::' .. #!/bin/perl -sp0777iX+d*lMLa^*lN%0]dsXx++lMlN/dsM0j]dsj $/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1 lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/) Please visit http://online.offshore.com.ai/arms-trafficker/
RE: Calling sequence
Very interesting problem, and a more complete answer would be j = 6, i = 4, and this is why: i = 2; j = i++ + ++i; Obviously, the j line is more interesting, so we'll talk about sequence of operations. The preincrement operator is done before everything else, so "++i" is done, giving i the value of 3, even before the addition, so you end up with "j = 3++ + 3" which equals 6. After the line is completed, i is incremented, causing i to be 3++ = 4. ~Patrick From: James On Wed, 28 Apr 1999, Glynn Clements wrote: # In gcc, # # if i = 2; # then j = i++ + ++i; # #what is the value of j. # # i++ == 2 # ++i == 3 # = j == 5 no. it's not. I typed this in: main() { int i = 2; printf ("%d", i++ + ++i);} and when i ran it i got 6 printed...
RE: Calling sequence
Very interesting problem, and a more complete answer would be j = 6, i = 4, and this is why: i = 2; j = i++ + ++i; Obviously, the j line is more interesting, so we'll talk about sequence of operations. The preincrement operator is done before everything else, so "++i" is done, giving i the value of 3, even before the addition, so you end up with "j = 3++ + 3" which equals 6. After the line is completed, i is incremented, causing i to be 3++ = 4. ~Patrick On my compiler it seems to do this: i = 2; j = i++ + ++i; It does the i = 2 just fine. So at the start of the j line i = 2. Now, it does i + ++i, and *then* it increments i the second time. So it becomes (2 + ++i)++; Actually I just tried it with a couple different compilers. g++ and gcc give me 5 for j while CC and cc both give me 7 for j. I assume that the GNU compilers are incrementing the i++ after then assignment is done, while the CC compilers are incrementing i++ before the addition begins. --Joe
RE: Calling sequence
Here is the ouput on our SGI server running IRIX 6.5 #include stdio.h main() { int i=2; int j = i++ + ++i; printf("%d %d\n",j,i); } Now, you think that j would be 7 and i would be four right? Here it is with g++/gcc (both give the same output): elvis 586% g++ b.c elvis 587% a.out 5 3 And now with the CC type compilers from SGI: elvis 588% CC b.c elvis 589% a.out 7 4 I'll have to take a look at the rest of what you said because something seems a little off, but this behaviour is totally wrong -- while the CC compilers are incrementing i++ before the addition begins. This is completely against the C standard, which means the post-increment is done after the assignment. If it does the increment before the assignment, it is a preincrement (++i). The reason it seems there is a preincrement on the first i is because the second i is preincremented. It doesn't surprise me that it may be a compiler- dependant thing on whether or not the first i sees the preincrement. On my gcc, both i's see the preincrement, and then i is postincremented due to the "i++". To show that this is the case, do the following (again probably compiler-dependant): +snip #include stdio.h void main(void) { int i=2; int p= ++i + ++i; printf("p=%d, i=%d\n", p, i); } +snip You still get the expected i = 4, but p is now 8 because i is preincremented twice (to 4) and then added together (for 8). All of this stems from both the compiler, OS, and machine used. It depends upon whether or not local copies of i are made for the addition, when the values are read from memory, etc. However, the values I have given are from linux gcc on an x86, and are what is expected from ANSI C. Pre-increment is done before everything, then addition, then assignment, then postincrement. On a UltraSparc w/ SunOS 5.5.1, you get j=7, i=4. This is because Sparc has local registers for the addition. Not to start a holy war, but I feel this is a bug in the hardware in this case. Sparc should not have cached the value of i after the first increment because it results in i == 3 == 4 when the final addition is made to assign to j. ~Patrick From: Joseph Keen Very interesting problem, and a more complete answer would be j = 6, i = 4, and this is why: i = 2; j = i++ + ++i; Obviously, the j line is more interesting, so we'll talk about sequence of operations. The preincrement operator is done before everything else, so "++i" is done, giving i the value of 3, even before the addition, so you end up with "j = 3++ + 3" which equals 6. After the line is completed, i is incremented, causing i to be 3++ = 4. ~Patrick On my compiler it seems to do this: i = 2; j = i++ + ++i; It does the i = 2 just fine. So at the start of the j line i = 2. Now, it does i + ++i, and *then* it increments i the second time. So it becomes (2 + ++i)++; Actually I just tried it with a couple different compilers. g++ and gcc give me 5 for j while CC and cc both give me 7 for j. I assume that the GNU compilers are incrementing the i++ after then assignment is done, while the CC compilers are incrementing i++ before the addition begins. --Joe
RE: Calling sequence
On Wed, 28 Apr 1999, Joseph Keen wrote: #include stdio.h main() { int i=2; int j = i++ + ++i; printf("%d %d\n",j,i); I beleive statements with multiple side effects are undefined in ISO C standard and that is why everyone is getting all sorts of weird answers, but I may be wrong. Kevin ... [EMAIL PROTECTED] `:::' Kevin Sivits ... .. ::: * `::.::' ::: .:: .:.::. .:: .:: `::. :' ::: :: :: :: :: :::::. ::: .::. .:: ::. `. .:' ::. ..:::.::' .. #!/bin/perl -sp0777iX+d*lMLa^*lN%0]dsXx++lMlN/dsM0j]dsj $/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1 lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/) Please visit http://online.offshore.com.ai/arms-trafficker/
RE: Calling sequence
Yeah, I asked a few professors here at school about it and they said that it's a fundamentaly undefined statement. Also, I've been meaning to ask you what the perl script at the bottom of your emails does. I beleive statements with multiple side effects are undefined in ISO C standard and that is why everyone is getting all sorts of weird answers, but I may be wrong. Kevin ... [EMAIL PROTECTED] `:::' Kevin Sivits ... .. ::: * `::.::' ::: .:: .:.::. .:: .:: `::. :' ::: :: :: :: :: :::::. ::: .::. .:: ::. `. .:' ::. ..:::.::' .. #!/bin/perl -sp0777iX+d*lMLa^*lN%0]dsXx++lMlN/dsM0j]dsj $/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1 lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/) Please visit http://online.offshore.com.ai/arms-trafficker/
Re: recv
James wrote: i'm trying to communicate with a server which sends output down a socket. The server sends a code and then some text (e.g 01: Connection Refused). What i'd like to do is just recv the first 2 bytes and act on them, instead of having to recv the whole line (i don't know how long the lines of text are, they can be changed), if i do a recv for 2 bytes i'll get '01' but then the next recv will get the rest of the text won't it? It depends upon the protocol: it will work with TCP, but not UDP (calling read(), recv() etc on a UDP packet will read the requested number of bytes and then discard the rest of the packet). i could recv 1 byte at a time, storing the characters in a buffer, until a newline was found (all output from the server ends in \n) but that sounds overly complicated. Why don't you just use fgets(), fscanf() etc? -- Glynn Clements [EMAIL PROTECTED]
Re: [rms@gnu.org: Re: still no egcs/gcc announcement]
From: Marc Lehmann [EMAIL PROTECTED] On Sun, Apr 25, 1999 at 10:58:51PM +, Jason wrote: [Announcement omitted.] The question that's on my mind is: what does this mean for pgcc in terms of its relationship to egcs/gcc? Oh, the faq entry on this is still quite correct. In the old gcc times, no merging was possible. Full Stop. With egcs, the door to to mergings (intelligent ones) was opened. This means that successful pgcc features (not all of it are) migrate into egcs. The difference between egcs and gcc has decreased steadily with regards to code quality and features. There are no strict guidelines on how the releases/snaoshots process for egcs will look like in the future, thats the steering committee's job in the coming weeks/months. However, taking over gcc maintainership means that the egcs development and releasde style will be carried over and applied to gcc. Will the optimizations be merged directly into the new source tree, or will it remain separate, distributed as patches to the egcs (well, actually gcc now) source? Has any of this even been determined yet? :) It will stay seperate as long as it still is useful! At the day where egcs is as good as pgcc in optimizing I will stop maintaining it ;) While this might not happen anytime soon, the difference between egcs and pgcc is decreasing as more and more pgcc features are also available (or even better implemented) in egcs. -- -==- | ==-- _ | ---==---(_)__ __ __ Marc Lehmann +-- --==---/ / _ \/ // /\ \/ / [EMAIL PROTECTED] |e| -=/_/_//_/\_,_/ /_/\_\ XX11-RIPE --+ The choice of a GNU generation | |
Re: C Compilers
g++ compiles C and C++ and it's worked for everything I've ever tried to compile. What are the differences between: gcc egcs pgc and which should i use? Last i tried, egcs wouldn't compile kernels. All i want is a good, quick C and C++ compiler that works 100% with all code. Also, where am i supposed to install a c compiler and how do i remove an existing one (after compiling the new one of course!)? -- +++ The program isn't debugged until the last user is dead. +++ [EMAIL PROTECTED] http://www.penguinpowered.com/~a_out
Re: gcc with optimization
Well, if it's breaking it then don't use it :) You probably don't need to anymore anyway. Most modern compilers perform as much optimization as possible when they compile anyway. The -O flag is there because back in the old days when it took a while to compile, trying to optimize at the same time would have been too much of a strain on the processor. Hi all, This is a really newbie question: After compiling my source files with the -O (or -O2) options, my executable file gives me bus errors. When I compile without the -O options, everything works flawlessly. Why is this happening and what can I do to fix it? anukool.
[rms@gnu.org: Re: still no egcs/gcc announcement]
From: Marc Lehmann [EMAIL PROTECTED] Ok. It was a busy time with both pgcc and egcs, but, finally, the official egcs - gcc merge was announced. Here's a copy: - Forwarded message from Richard Stallman [EMAIL PROTECTED] - Subject: New maintenance team for GCC We are pleased to announce a new GCC maintainer. The EGCS Steering Committee is taking over as the (collective) GNU maintainer of GCC--and changing its name to the GCC Steering Committee. The GNU maintainer of a package has the responsibility for deciding what changes to install, fixing bugs, and making releases. The development process for GCC will be essentially the same as has been used for EGCS, and the EGCS CVS archive will become the GCC CVS archive. Day-to-day technical details will be handled by the release manager (currently Jeff Law) appointed by the steering committee. We would like to thank Richard Kenner for his work as the GCC maintainer for the 2.5.x through 2.8.x releases of GCC. - End forwarded message - -- -==- | ==-- _ | ---==---(_)__ __ __ Marc Lehmann +-- --==---/ / _ \/ // /\ \/ / [EMAIL PROTECTED] |e| -=/_/_//_/\_,_/ /_/\_\ XX11-RIPE --+ The choice of a GNU generation | |
Re: dynamic loding
hi, try ELF-HOWTO at www.linux-howto.com Raju On Fri, 23 Apr 1999, Yasushi Shoji wrote: hi all, is it possible for ELF executable to be run without shared libraries which is linked at compile time but not needed at run time? for example, there is an ELF executable called foo, and foo needs libbar.so for function bar(). my understanding is that kernel will load libbar.so into memory when foo calls function bar. if foo doesn't call function bar, libbar.so is not loaded at all. then why does libbar.so have to exist when foo is executed? is it just a limitation of ELF? i think even under the ms-windows, linked(?) dll doesn't have to exist if a binary doesn't call it. -- yashi ps. pointers to books, web, whatever is also appreciated
Re: the itoa function
James wrote: If you want to convert ints to strings try this: ... #include string.h sprintf(), like printf() and fprintf(), is declared in stdio.h. -- Glynn Clements [EMAIL PROTECTED]
Re: lots of qs. 2
Chetan Sakhardande wrote: ) If a process cannot change anothers data structures, how does a job control shell make its child a proces grp leader ? A process group leader is a process for which getpgid() == getpid() Consequently, you can make a process a process group leader with setpgid(pid, 0); A process can make itself a process group leader with setpgid(0, 0); or setpgrp(); 2) In select system call, when is an fd ready for writing ? When a call to write(fd, ...) won't block. 3) WHEN INETD FORKS A CHILD(SERVER) FOR A REQUEST, HOW DOES IT DO SETUID AND SETGID FO THE NEW SERVER PROCESS THAT IT JUST FORKED(I.E. HOW DOES IT KNOW WHICH UID TO SET TO ) The uid/gid are specified in the fifth column of /etc/inetd.conf. -- Glynn Clements [EMAIL PROTECTED]
Re: A timer example
On Thu, 15 Apr 1999, Victor J. McCoy wrote: I need to send a message at 10 Hz. All the timer functions I've seen (sleep(), etc.) are on a second boundary. Is there a way to do it so as to not be in an endless loop waiting for the 0.1 second time frame to finish? man 3 usleep or for asynchonous notification see man setitimer Karlis
Re: Program error
Anubhav Hanjura wrote: Trying to print *ip as a character when I apply post increment operator gives me 'D' and for pre-increment it gives me a bus error. Why? You are using a big-endian processor (e.g. 680x0), right? #includestdio.h int main() { char *c_array; int *ip; c_array = (char *)malloc(100); strcpy(c_array,"ABCDEFHIFGHIJKLMN"); ip = (int *)(++c_array); return 0; } The value of the expression: *(int *)(c_array) depends upon sizeof(int) and the processor's byte order: 32-bit little-endian: 0x44434241 32-bit big-endian: 0x41424344 64-bit little-endian: 0x4847464544434241 64-bit big-endian: 0x4142434445464748 Calling printf("%c", *(int *)(c_array)) will display either 'A' (0x41), 'D' (0x44) or 'H' (0x48) depending upon sizeof(int) and the processor's byte order. Using pre-increment addressing will attempt to read a 32-bit value from an odd address, which will cause a bus error on processors which require aligned memory access (80x86 doesn't; AFAIK 680x0 does). -- Glynn Clements [EMAIL PROTECTED]
Re: X window managers
On Thu, 15 Apr 1999, Nathan Grass wrote: a friend and i were concidering creating our own window manager and we were wondering if anyone knows any good books/webpages on the subject. With Gnome and KDE out there in 1.0 versions why would you want to start on that yourself? Both environments allow for a lot of customization and you could create a new desktop look and feel by changing some of the existing code. You could add new widgets (panels, buttons, whatever) that can be added (or patched) to a widely distributed system that is already out there. That's just what I would do if I wanted to make a big impact on how my window manager worked... // [EMAIL PROTECTED] -=- This sig footer was last updated Apr 13 1999 -=- \\ | Nathan Grass http://www.zaz.net/| | Employer: Metamor ITShttp://www.metamor-its.com/| | zaz on DALnetICQ: 35510843 | \\ -=- Unless otherwise noted, expressed views are my opinions. -=- // well... actually we were thinking of doing this as a project for college. we have to take a class in which we do some kind of software developing and we both are very much into linux. the teacher is also very into linux and is willing to help us out on it. so you want to know why we want to do it. Answer: because we can, and beecause it would be fun. Scott W. Amory| ...the Force is what gives the Jedi his power. [EMAIL PROTECTED] | It's and energy field created by all living http://www.rowan.edu/~amory | things. It surrounds us and penetrates us. | It binds the galaxy together. - Obi-Wan Kenobi ---
Re: strupr ??
On Fri, 9 Apr 1999, Glynn Clements wrote: [EMAIL PROTECTED] wrote: I wonder if there are some functions which converts strings to/from lower/upper case ?? In DOS/WIN there was strupr funtio. When can i find it on Linux ?? #include ctype.h void strupr(char *p) { while (*p) *(p++) = toupper(*p); } Thanks it will help me !!! -- Zbigniew Zagorski [EMAIL PROTECTED]
Re: processes
On Tue, 13 Apr 1999, James wrote: if i know the pid of a process, how can i find out it's status? (i.e running, blocked, ready, zombie, invalid pid...) cat /proc/pid/status (or in custom programm - read this file and extract necessary information. If directory /proc/pid does not exist - invalid pid.) Karlis
Re: array filling problem
On Sat, 10 Apr 1999, Dan Jue wrote: The above creates a matrix of [4][4]; that is, each dimension varies from [0] to [3]. a[0][3] is the last element of the first row; a[0][4] is infact the first element of the second row which is better represented by a[1][0]. Are we allowed to assume that row-major order arrays are totally contiguous in memory for any platform (by your example of address a[0][4])? For arrays of structures or objects (or some other big unit), is it not possible for their locations in memory to be non-contiguous? You are right; you cannot just assume the whole array is allocated in one contiguous location. I was merely trying to explain what was happening in the code originally posted. In that code only a few bytes of memory were assigned, as such one can pretty much be sure that they are in one contiguous location. Of course there is no guarantee Also i'm assuming that you cannot access a[0][4] directly because wouldn't that cause an out-of-bound subscript error? So you would instead do some manual pointer arithmetic to get that address, right? I thought one of the reasons for speed of C (compare to other languages) was because it wasn't checking for boundaries. After all, this is the reason for all those "buffer overflow" bugs that have surfaced recently. Please correct me if I am wrong. cheers, Hossein
Re: array filling problem
Dan Jue wrote: int main () { const dim = 5; float a[dim-1][dim-1]; The above creates a matrix of [4][4]; that is, each dimension varies from [0] to [3]. a[0][3] is the last element of the first row; a[0][4] is infact the first element of the second row which is better represented by a[1][0]. Are we allowed to assume that row-major order arrays are totally contiguous in memory for any platform (by your example of address a[0][4])? Yes. For arrays of structures or objects (or some other big unit), is it not possible for their locations in memory to be non-contiguous? No. Also i'm assuming that you cannot access a[0][4] directly because wouldn't that cause an out-of-bound subscript error? No. There is no subscript checking in C. a[0][4] means exactly the same thing as *(a[0] + 4). So you would instead do some manual pointer arithmetic to get that address, right? Array accesses are just a convenient syntax for pointer arithmetic. -- Glynn Clements [EMAIL PROTECTED]
Re: compiling
On Sun, 11 Apr 1999, Darius Blaszijk wrote: # Recently I came across a package witch I want to use in my programs. The # package consists of a header file (interface) and a *.c source code file # (implementation). How can I use these files in my application? If I try # to compile my application the compiler gives me this message: undefined # reference. By your use of 'interface' and 'implementation' i'd say you've used modula-2 or pascal... and like those languages you must tell your C compiler to include the header file. Assuming the header is called foo.h and the source is called foo.c. Put them in the same directory as your c program (called bar.c in this example). in the top of bar.c put a line like this: (it goes along with the #include stdio.h and similar lines) #include "foo.h" this tells gcc to look in the current directory (which is what "" means. means 'look in standard include locations') then when you come to compile, type a command line like: gcc -Wall -o bar bar.c foo.c the -Wall just makes gcc really really picky about your code (a good thing). -o tells it what to call the executable (the first thing after the -o) and bar.c and foo.c are the sources to compile. You need to compile foo.c as well. If it was given as an object file (foo.o) then you'd do something slightly different ( gcc -Wall -c bar.c /* creates bar.o */ gcc -Wall -c foo.c /* creates foo.o */ gcc bar.o foo.o -o bar /* links them together into an executable called 'bar' */ ) -- +++ If at first you don't succeed, you must be a programmer +++ [EMAIL PROTECTED] http://www.penguinpowered.com/~a_out
Re: compiling
Hello! On Sun, 11 Apr 1999, Darius Blaszijk wrote: Recently I came across a package witch I want to use in my programs. The package consists of a header file (interface) and a *.c source code file (implementation). How can I use these files in my application? What you'll want to do probably is create a library and link it with your app. I forget exactly what you're supposed to do to create a static library (has something to do with the ar command), but it's like making a tar (in this case just ar) file of the object files... But if you just want to get it to work, try this: $ gcc app.c file1.c file2.c file3.c -o app Or something like that... I think that might work for you... Hopefully someone else will be able to be more help than I; my mind is numbed from doing homework for school tomorrow :) -Brett
Re: compiling
Hello again! :) Okay, well, I thought I was going to go back to my homework and forget about this, but of course I had to look up how to make a static library for our friend Darius here :) All right, what you want to do is compile each .c that you want in the library into an object file, .o You might do something like: % foreach i (*.c) gcc -c $i end or with Bash: $ for i in *.c do gcc -c $i done to get all those .o files... Okay, so now you make a static library from the .o files like this: $ ar r mylib.a file1.o file2.o file3.o $ ranlib mylib.a And now you've got a static library to use! $ gcc app.c mylib.a -o app You can delete an object file from your library with ar like this: $ ar d mylib.a badone.o Does that help... ? I hope so :) Have fun! -Brett
Re: array filling problem
On Sat, 10 Apr 1999, Darius Blaszijk wrote: #includestdio.h int main () { const dim = 5; float a[dim-1][dim-1]; The above creates a matrix of [4][4]; that is, each dimension varies from [0] to [3]. a[0][3] is the last element of the first row; a[0][4] is infact the first element of the second row which is better represented by a[1][0]. This becomes clearer if you look at the whole thing as a pointer. "a" is just a pointer and a[i][j] is, in this case, the pointer incremented i*4+j. I hope this helps. Hossein
Re: array filling problem
int main () { const dim = 5; float a[dim-1][dim-1]; The above creates a matrix of [4][4]; that is, each dimension varies from [0] to [3]. a[0][3] is the last element of the first row; a[0][4] is infact the first element of the second row which is better represented by a[1][0]. Are we allowed to assume that row-major order arrays are totally contiguous in memory for any platform (by your example of address a[0][4])? For arrays of structures or objects (or some other big unit), is it not possible for their locations in memory to be non-contiguous? Also i'm assuming that you cannot access a[0][4] directly because wouldn't that cause an out-of-bound subscript error? So you would instead do some manual pointer arithmetic to get that address, right? Thanx for any response. Best Regards, * Dan Jue, CMSC UMCP *Linux '99 * ** ReSiTaNcE iS FuTiLe!*
Re: array filling problem
On Sat, 10 Apr 1999, Dan Jue wrote: # Are we allowed to assume that row-major order arrays are totally # contiguous in memory for any platform (by your example of address Probably not. # a[0][4])? For arrays of structures or objects (or some other big unit), # is it not possible for their locations in memory to be non-contiguous? Yes. # Also i'm assuming that you cannot access a[0][4] directly because wouldn't # that cause an out-of-bound subscript error? So you would instead do some No. C Does not do array bounds checking. You could quite happily run this C program: main(){int f[2]; f[12345]=1;} and when you run it all you get is an ever helpful 'Bus Error'. # manual pointer arithmetic to get that address, right? a[0][4] is a legal array subscript. If the element you're telling it to reference is part of the array then nothing bad will happen, if however the array isn't stored contiguously then you may try and access memory you have no rights to access and crash the program. # Thanx for any response. # # # Best Regards, # # # * Dan Jue, CMSC UMCP *Linux '99 * # ** ReSiTaNcE iS FuTiLe!* # # # # -- +++ If at first you don't succeed, you must be a programmer +++ [EMAIL PROTECTED] http://www.penguinpowered.com/~a_out
Re: Arrays is confusing
--- Sent through Global Message Exchange - http://www.gmx.net
Re: Trapping special characters
[PS: Please don't post HTML to the list] Anubhav Hanjura wrote: How can I trap special characters like say ALT-A to ALT-Z from my program? It depends upon what the terminal does with Alt-key. The three most common options are: a) Ignore the Alt. b) Send ESC-key c) Send the ASCII code plus 0x80 I want the solution to be portable across platforms so that I can do the same on Windows also. Sorry, but Windows isn't really compatible with anything except Windows. -- Glynn Clements [EMAIL PROTECTED]
Re: Arrays is confusing
ZioBudda wrote: On Thu, 8 Apr 1999, Henk Jan Barendregt wrote: the line is executed. The result will be i[0] = 0 I Think i[0] = 1 i[1] = unknown i[2] = 3 and so on... I have tested it with a loop and the results were : i[0] = 0 i[1] = unknown i[2] = 2 etc, etc, If you change the lin toi[++j] = j++; then you wil get the results like you expected exept that i[0] = unknown. Henk Jan
Re: settings
(I wonder if this is what you mean...) It took me a while to figure out this feature. I know that on my machine if you hold down ctrl and alt and press the minus key, that will make all your windows smaller so more will fit on the screen. You probably already know that, but jic. On Wed, 7 Apr 1999, Anubhav Hanjura wrote: I have just installed linux and when I start X window interface by typing xstart, I am getting start menu having much bigger fontsize than I want . How do I correct it? Please reply as soon as possible thanks in advance anubhav a n u b h a v h a n j u r a __ E-Mail: [EMAIL PROTECTED] Telephone: ( 091 )-0124-342971-302 [O]
Re: Arrays is confusing
The output is actually correct for what you are telling it to do. You are telling to to assing i[j++] to j++. Now, i[j++] is the same as saying i[0] because j++ only gets incremented after it is used. You probably want something like i[++j] here. The =j++ does the same thing. So you are assigning i[0] = 0. And when you printf the first vaule i[0] is 0 so the output is correcct. The rest of it is random garbage because it's never been assigned a value. Why does this code give the strange output they give? #includestdio.h main() { int i[4] ; int j = 0; i[j++] = j++; printf("%d %d %d %d\n",i[0],i[1],i[2],i[3]); return 0; }
Re: Arrays is confusing
Anubhav Hanjura wrote: #includestdio.h main() { int i[4] ; int j = 0; i[j++] = j++; /* you put the previous lin in a loop j will be increment by 2 every time the line is executed. The result will be i[0] = 0 i[1] = unknown i[2] = 2 i[3] = unknown i[4] = 4 etc etc . To prevent this replace by i[j++] = j; */ printf("%d %d %d %d\n",i[0],i[1],i[2],i[3]); return 0; }
Re: Arrays is confusing
Good $daytime, Date: Thu, 8 Apr 1999 16:39:22 +0530 From: Anubhav Hanjura [EMAIL PROTECTED] To: UnixC [EMAIL PROTECTED] Subject: Arrays is confusing Anubhav Why does this code give the strange output they give? Pardon my ignorance, but what results did you regard as strange? It depends heavily on what you expected :) In general, you can't safely rely on any particular order of calculations -- with regard to side effects. There are four operations: 1) '++' within lvalue; 2) '++' within rvalue; 3) '[]', and 4) '='. Dependencies are: ++ after [] [] ++ after = / \ = after [] = ++ | ++ Possible orders are: a) 3 1 4 2 [] ++ = ++ means i[0] = 1 b) 3 4 2 1 [] = ++ ++ means i[0] = 0 c) 3 4 1 2 [] = ++ ++ means i[0] = 0 However, if optimizing compiler tries to postpone evaluation of 'j' until next usage, result most likely will be b). Regards, Willy. -- "No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov Shall bring us to our goal, | Information Technology Division But iron sacrifice | Chelyabinsk State University Of Body, Will and Soul."| mailto:[EMAIL PROTECTED] +7 3512 156770 R.Kipling | http://www.csu.ac.ru/~willy VVF1-RIPE
Re: Thread hang problem
FWIW, I cannot reproduce the problem; the program always completes all 1 iterations. This is with gcc 2.8.1, binutils 2.9.1, glibc 2.0.7c, Linux 2.2.5. -- Glynn Clements [EMAIL PROTECTED]
Re: ip address
James wrote: if i know a device's name (eth0 etc), how can i find out it's IP address? i've looked in the ifconfig source but there's so much extra stuff in there it's hard finding the relevant bits. Try the attached program. -- Glynn Clements [EMAIL PROTECTED] #include sys/ioctl.h #include sys/socket.h #include netinet/in.h #include net/if.h #include arpa/inet.h #include unistd.h #include stdio.h static struct in_addr device_address(const char *if_name) { struct ifreq ifr; struct sockaddr_in *addr; int s; s = socket(PF_INET, SOCK_DGRAM, 0); if (s == -1) { perror("socket"); exit(1); } strcpy(ifr.ifr_name, if_name); ifr.ifr_name.sa_family = AF_INET; if (ioctl(s, SIOCGIFADDR, ifr) 0) { perror("ioctl(SIOCGIFADDR)"); exit(1); } addr = (struct sockaddr_in *) ifr.ifr_addr; close(s); return addr-sin_addr; } int main(int argc, char **argv) { struct in_addr addr; if (argc 2) { fprintf(stderr, "Usage: %s interface\n", argv[0]); exit(1); } addr = device_address(argv[1]); printf("IP Address: %s\n", inet_ntoa(addr)); return 0; }
Re: Another bit question
Anukool Lakhina wrote: Given two 32-bit numbers, I want to decide which number has more bits set. And what the difference in the number of bits set is. So for example, if Num1=111...011 and Num2= 011...001, I'm trying to write an efficient function numBitsSet() that returns 2 if Num1 has 2 more bits set than Num2 and -2 if Num2 has 2 more bits set than Num1. In this case, it'll return 2. Yes, I can do this easily by looping through the two numbers and storing a counter etc etc. But I need an efficient way to do this - I'm trying to do this by using a combination of xors or something. Please email me if you have any suggestions. static const unsigned char count[0x100] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 8, 8, }; static int numBits8(unsigned int x) { return count[x 0xff]; } static int numBits(unsigned int x) { return numBits8(x 24) + numBits8(x 16) + numBits8(x 8) + numBits8(x); } int diffBits(unsigned int a, unsigned int b) { return numBits(a) - numBits(b); } -- Glynn Clements [EMAIL PROTECTED]
Re: fledgling
On Tue, 6 Apr 1999, Glynn Clements wrote: # In no less than 5 months I will be graduating and # moving on to college. I plan to study computer # engineering. I know that I *will* be able to skip some # courses, especially if it has to deal with # programming. # # It depends upon the nature of the course. Being able to program won't # necessarily get you all that far on a Computer Science degree course; # I don't know about Computer Engineering. that's sort of what i'm doing (i'm doing BSc (hons) S/Ware Eng.) and the C programming was mainly boring, but i'm glad i did it all the same, the bit we did with pointers really helped. For some reason i'm also doing an Information Systems module which is so boring i keep falling asleep :) (it's the boring waffly side of computing, like Systems Analysis but less diagrams and more words) -- +++ If at first you don't succeed, you must be a programmer +++ [EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit
Re: Another bit question
I hope this is what you want...After much thought I still feel uneasy about using two function calls per run. Is there any better method?? Meanwhile I am thinking of a better solution. ciao --program code- #includestdio.h unsigned int numbitset(unsigned int x) { unsigned int n=0; for(;x0;x=1) /* shift number right and test against set bit */ if( x 01 ) { n++; } return n; } int main(void) { int i,j; printf("enter first number: "); scanf("%d",i); printf("enter secon number: "); scanf("%d",j); printf("difference of bits set in %d and %d = %d\n",i,j,numbitset(i)-numbitset(j)); return 0; } -Original Message- From: Anukool Lakhina [EMAIL PROTECTED] To: [EMAIL PROTECTED] [EMAIL PROTECTED] Date: Tuesday, April 06, 1999 5:27 AM Subject: Another bit question Hello all, Given two 32-bit numbers, I want to decide which number has more bits set. And what the difference in the number of bits set is. So for example, if Num1=111...011 and Num2= 011...001, I'm trying to write an efficient function numBitsSet() that returns 2 if Num1 has 2 more bits set than Num2 and -2 if Num2 has 2 more bits set than Num1. In this case, it'll return 2. Yes, I can do this easily by looping through the two numbers and storing a counter etc etc. But I need an efficient way to do this - I'm trying to do this by using a combination of xors or something. Please email me if you have any suggestions. Thank you. anukool.
Re: ppp
On Tue, 6 Apr 1999, James wrote: what's the most reliable way of detecting when a ppp link is up? so far i've been looking in /proc/net/dev, but the ppp entry in that hasn't gone away and i'm nolonger online. A simple name lookup (nslookup www.netscape.com) should tell you. You may also try to ping a server in your ISP. Based on return value of the ping, you can detect if the link is up (great for scripts). Also check out /sbin/route and /sbin/ifconfig. cheers, Hossein
Re: Another bit question
Hi, Just remove those two printf's which print value of a and b in the function numbitset() ciao, anubhav -Original Message- From: Glynn Clements [EMAIL PROTECTED] To: Anukool Lakhina [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] [EMAIL PROTECTED] Date: Tuesday, April 06, 1999 10:14 AM Subject: Re: Another bit question Anukool Lakhina wrote: Given two 32-bit numbers, I want to decide which number has more bits set. And what the difference in the number of bits set is. So for example, if Num1=111...011 and Num2= 011...001, I'm trying to write an efficient function numBitsSet() that returns 2 if Num1 has 2 more bits set than Num2 and -2 if Num2 has 2 more bits set than Num1. In this case, it'll return 2. Yes, I can do this easily by looping through the two numbers and storing a counter etc etc. But I need an efficient way to do this - I'm trying to do this by using a combination of xors or something. Please email me if you have any suggestions. static const unsigned char count[0x100] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 8, 8, }; static int numBits8(unsigned int x) { return count[x 0xff]; } static int numBits(unsigned int x) { return numBits8(x 24) + numBits8(x 16) + numBits8(x 8) + numBits8(x); } int diffBits(unsigned int a, unsigned int b) { return numBits(a) - numBits(b); } -- Glynn Clements [EMAIL PROTECTED]
Re: Another bit question
Here is another solution.. how was the first ?? I have not tested this extensively just for some sample values and it worked fine ciao, anubhav program code #includestdio.h int numbitset(unsigned int x,unsigned int y) { unsigned int a=0; unsigned int b=0; register int asetbit=0; register int bsetbit=0; for(;x0 || y0 ; x = 1, y = 1) { a = x 01; printf("a=%d\n",a); b = y 01; printf("b=%d\n",b); if( (a^b) (a)) asetbit++; else if ((a^b) (b)) bsetbit++; else ; } return asetbit - bsetbit; } int main(void) { int i,j; printf("enter first number: "); scanf("%d",i); printf("enter secon number: "); scanf("%d",j); printf("difference of bits set in %d and %d = %d\n",i,j,numbitset(i,j)); return 0; } program code ends -Original Message- From: Glynn Clements [EMAIL PROTECTED] To: Anukool Lakhina [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] [EMAIL PROTECTED] Date: Tuesday, April 06, 1999 10:14 AM Subject: Re: Another bit question Anukool Lakhina wrote: Given two 32-bit numbers, I want to decide which number has more bits set. And what the difference in the number of bits set is. So for example, if Num1=111...011 and Num2= 011...001, I'm trying to write an efficient function numBitsSet() that returns 2 if Num1 has 2 more bits set than Num2 and -2 if Num2 has 2 more bits set than Num1. In this case, it'll return 2. Yes, I can do this easily by looping through the two numbers and storing a counter etc etc. But I need an efficient way to do this - I'm trying to do this by using a combination of xors or something. Please email me if you have any suggestions. static const unsigned char count[0x100] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 8, 8, }; static int numBits8(unsigned int x) { return count[x 0xff]; } static int numBits(unsigned int x) { return numBits8(x 24) + numBits8(x 16) + numBits8(x 8) + numBits8(x); } int diffBits(unsigned int a, unsigned int b) { return numBits(a) - numBits(b); } -- Glynn Clements [EMAIL PROTECTED]
Re: fuzzy logic library
Quoting Darius Blaszijk [EMAIL PROTECTED]: Is there anybody that knows if there are fuzzy libraries that I can download? I have tried everything but I can't find them. Are there good archives wich I can trie? Thanks, Darius Blaszijk Hi there, There are some fuzzy logic libraries available; some free, some commercial. There is a book called "C++ Neural Networks and fuzzy logic". In which a few classes are developed for fuzzy logic and Neural Nets. I am also interested in the subject. Let me know if you find anything; especially if it can use "mif" files used by Fuzzy Logic Toolbox of Matlab (the toolbox is very intituive in designing fuzzy systems, it saves all the information about the system in plain text files with "mif" extension--the drawback of the toolbox is that it is EXTREMELY slow, and I mean SSLLOOWW). Hossein S. Zadeh -- This mail sent (using IMP) through RMIT Business http://www.bf.rmit.edu.au
Re: fledgling
Canul Podkopayeva wrote: In no less than 5 months I will be graduating and moving on to college. I plan to study computer engineering. I know that I *will* be able to skip some courses, especially if it has to deal with programming. It depends upon the nature of the course. Being able to program won't necessarily get you all that far on a Computer Science degree course; I don't know about Computer Engineering. I would like to know how database programming stands though. Can someone tell me a real world database program that would be needed? I want to test what I know. The database course that I did (BSc Comp Sci) covered topics such as relational algebra, query optimisation, normal forms (1st/2nd/3rd/Boyce-Codd normal forms) and normalisation, SQL, etc. Hopefully you should get a syllabus and a reading list, which would give you a better idea of what you will cover. -- Glynn Clements [EMAIL PROTECTED]
Re: Database Programming
On Sat, 3 Apr 1999, Tim - HOWTO Coordinator wrote: } Hi, } } Thanks for your response Karl, it's greatly appreciated. } } } Could someone recommend some documentation, sites/links, books or code } } snippets for database programming under C? } } Hi Tim, I'm not clear what your in mind of doing. Do you want to } write a special database application, or do you want to write an } application "front end" to an existing data base. I use postgeSql, the } Well, to make a long story short, I'm not sure what my options are, I just } know that I'd like to be able to do it in C. This is *not* to stir up a } discussion of "what's best to use for different circumstances" like } re-inventing the wheel when I could do the same thing in a few lines of } Perl. I just want to do it in C, so if you want to flame go for it, just } do it privately, not to the list. Don't be silly Tim. This list has several Tigers at C who will make anyone trying to pontificate (flame) look like the ass they are. } } My curiosity was stirred when I found an old book at work called: C Data } Base Development. In short it claims to teach data base theory and design } and provides a complete package of data base management software in C } source (disks not provided). What a pity! The code has been tested with over ten } different compilers, include Turbo C, Microsoft C, Lattice C, and Aztec } C86. I'm not sure my C is strong enough at this point to figure out what } needs to be done with the source given in the book to get it to work under } Linux if it's even possible. This should not be a big problem. I am *Learning* C from a book "New C Primer Plus", Sams and it is written assuming your using Unix or Microsoft C or Borland Turbo C. I have had no problem with this book just following the Unix way. Problems occur when you call the math library and write to the screen and a few places like that. I think you can find these and fix them. Aside. I made a serious blunder and was grilled for it by the people giving us new libraries and compilers. They said I am stupid not to get the latest compiler called "egc". I returned with " I am using the very latest Red Hat version and it was written and compiled by the old gcc. If it's good enough for that, it's good enough for me". That ended that. } } CDATA (The Cheap Data Base Management System) is mentioned, but I'm not } even sure what this is and whether or not it's widely known or is } something the author has come up with. I haven't even begun reading the } book, b/c I'm not sure if in the long run it's worth the time and/or } effort. } Depends what you want from the data base. A flat data base is simple but has limited use. From this kind of device you enter data all into one table. You can sort the table and like that depending on the tools you write/borrow. The SQL database has a lot of added features that allow it to hold giant amounts of data and work with it. Many users and tight security. } The postgeSQL "front end" is pretty good and you learn to use it } to make your data base and then retrive specific data. } I'm familiar with postgreSQL, but haven't used it very much as of yet. } } Data base is not simple! They have a whole new set of jargon to } knock you off your feet...:-) } I have no doubts about this comment. I am green to programming in C as it } is, which is why I turned to the list for some sort of guidance. ;) } Most programers I have known were old by today's standard but they all wrote an editor at some point in their learning career. Since I have been forever interested in writing code they all gave me their editors all written for dos. I use joe in Linux for everything. Using gcc is simple. I use a user login xterm window and make a directory for my C stuff. Write the source code with joe naming it filename.c for straight C compile. GCC has lots of helpful error messages. Getting the source code to do what you want it to do is not simple. } Best Regards, } Tim } } -- } Linux HOWTO coordinator } [EMAIL PROTECTED], [EMAIL PROTECTED] (HOWTO's) } [EMAIL PROTECTED] (Home) } [EMAIL PROTECTED] (Work) } http://wallybox.cei.net:5119/cgi-bin/pageme.cgi (Alpha Pager) } } D I P C }The system that enables you to write distributed programs...the }easy way! } http://wallybox.cei.net/dipc/ } } Best wishes - Karl F. Larsen, [EMAIL PROTECTED] (505) 524-3303 -
Re: insane
Canul Podkopayeva wrote: I have a really messed up problem I'm trying to compile and install libcap then libnet. And I keep getting reports of missing header files. /usr/include/net : if.h This should exist on all versions of libc. However, on libc-5, it contains just: #include linux/if.h etc.. /usr/include/netinet : ethernet.h This doesn't exist on either libc. Try linux/if_ether.h for libc-5, or netinet/ether.h for libc-6. I have some of the headers, but for some reason I don't have the others. Can someone pelase tell me where I can get these header files? They are distributed as part of libc. -- Glynn Clements [EMAIL PROTECTED]
Re: terminal
James wrote: how do i turn off the cursor This is terminal-specific; some terminals may not allow the cursor to be disabled. If it can be done, you need to send the string which corresponds to the `civis' terminfo entry (`vi' termcap entry). and make my programs accept characters typed into a terminal without you having to press enter first? Put the terminal into raw mode using tcsetattr(). -- Glynn Clements [EMAIL PROTECTED]
Re: overlapping two gif files
here ya go, this should be perfect. http://www.unimelb.edu.au/fly/fly.html use this, or just the gd lib. -Joe Wei Weng wrote: No. That is not what i meant. I am looking for a way or a as small as possible program that I can run under command line that can overlap two gifs. say the command is called combinegif. so it would be like combinegif 1.gif 2.gif and it will generate like a.gif and the output will be 1.gif with 2.gif on the top. It would be even better if the program can specify the position of 2.gif on top of 1.gif based on coordinates. (in the case of 2.gif is smaller than 1.gif) What should i do? :) On Fri, 2 Apr 1999, Jakob Andreas Baerentzen wrote: On Fri, 2 Apr 1999, Wei Weng wrote: can anyone give me some hints or suggestions on how I could write a program to overlap two gif files together? Or simply, is there any program out there that can do the work for me? what do you mean by overlapping two gifs together? Anyway, I think you can use xv, gimp or some of the ImageMagick tools. All are part of the RedHat distributions. ImageMagick is also a library, so you can use it in your own programs. Andreas -- Wei Weng | idol of the week: Utada Hikaru| Part time oracle developer | CD of the week: first love| Full time J-ENT! NERD! (^^;; | o/~You are always gonna be my love o/~| --
Re: Database Programming
On Sat, 3 Apr 1999, Tim - HOWTO Coordinator wrote: } } Could someone recommend some documentation, sites/links, books or code } snippets for database programming under C? Hi Tim, I'm not clear what your in mind of doing. Do you want to write a special database application, or do you want to write an application "front end" to an existing data base. I use postgeSql, the data base shipped with Red Hat 5.2 that is pretty well documented by several .ps files that come with it. The postgeSQL "front end" is pretty good and you learn to use it to make your data base and then retrive specific data. Data base is not simple! They have a whole new set of jargon to knock you off your feet...:-) } } I'm looking for something that will start off pretty slow and won't be too } overwhelming if that's at all possible. ;) } } Any and all help would be greatly appreciated. } } Best Regards, } Tim } } -- } Linux HOWTO coordinator } [EMAIL PROTECTED], [EMAIL PROTECTED] (HOWTO's) } [EMAIL PROTECTED] (Home) } [EMAIL PROTECTED] (Work) } http://wallybox.cei.net:5119/cgi-bin/pageme.cgi (Alpha Pager) } } D I P C }The system that enables you to write distributed programs...the }easy way! } http://wallybox.cei.net/dipc } } Best wishes - Karl F. Larsen, [EMAIL PROTECTED] (505) 524-3303 -
Re: compiling with .so library files
On Sat, 3 Apr 1999, D. Jackson Peacock wrote: Hi. $ gcc -o gtktest gtktest.c You need to use $ gcc `gtk-config --cflags` `gtk-config --libs` gtktest.c -o gtktest Or you could write this as well: $ gcc -I/usr/local/lib/glib/include -I/usr/local/include \ -I/usr/X11R6/include -L/usr/local/lib -L/usr/X11R6/lib -lgtk \ -lgdk -lglib -lXext -lX11 -lm gtktest.c -o gtktest However, the first method is much easier to remember ofcourse. Good luck! Torbjørn S. Kristoffersen [EMAIL PROTECTED]
Re: Type casting with malloc()
holotko wrote: Let's say I want to dynamically allocate some memory to an object that I am creating using malloc(). Traditionally I do the following: ObjectType *objectpointer; /* Decl. of pointer to object */ objectpointer = (ObjectType *)malloc(sizeof(ObjectType)); My question. Do I really need to add the type cast (ObjectType *) before the call to malloc() ? In ANSI C, no. In KR C yes. Traditionally I have always been taught to include the cast. However, some references say that a cast was ONLY required in earlier versions of C prior to standard ANSI C. Nonetheless I always type cast as that is how I have done it for years and years. Do I really need the cast? ANSI C defines malloc() as returning a `void *', while KR C defines it as returning a `char *'. You can implicitly cast to or from void pointers, but casting between other pointer types requires a cast. More precisely, do I really need the cast using gcc? Not if you're using an ANSI libc (e.g. any of the ones which are used on Linux). -- Glynn Clements [EMAIL PROTECTED]
Re:
Darius Blaszijk wrote: Is there any compiler/editor/debugger-package anvailable from the internet? Or am I missing something here? I've noticed that MC has an edit feature which shows source code using different colours. I find this very helpfull. You can use wpe or xwpe for this. When you have bought the the RedHat box with book etc. Then you alse have the application cdrom with Code Crusader on it. Henk Jan
Re: your mail
Good $daytime, To do some programming I use for instance EMACS. When I'm done I exit EMACS and run GCC and then run the program to see if it does the thing I want it to do. This procedure is time consuming and not eficient. There is no need to exit any editor. If you're running X windows, you have both emacs and xterm at the same time. If not, you may open one console for editor and another for your shell. But there's a better way! Try `M-x compile' -- emacs will read gcc output in another buffer. Clicking mouse-2 over error message will bring you to the line in question -- no need for extra IDE. Is there any compiler/editor/debugger-package anvailable from the internet? Or am I missing something here? I've noticed that MC has an edit feature which shows source code using different colours. I find this very helpfull. There are many IDE-like products. To see a few, look at freshmeat.net appindex, section 'Development'. Well, if you're looking forward to "attend the Church of Emacs" :), try `M-x font-lock-mode'. Emacs has nice syntax highlighting -- and knows C/C++ to some extent. Hope this helps... Regards, Willy. -- "No easy hope or lies| Vitaly "Willy the Pooh" Fedrushkov Shall bring us to our goal, | Information Technology Division But iron sacrifice | Chelyabinsk State University Of Body, Will and Soul."| mailto:[EMAIL PROTECTED] +7 3512 156770 R.Kipling | http://www.csu.ac.ru/~willy VVF1-RIPE
Re: your mail
I don't use emacs much but I use vim. One way you can do what you're trying to do is by first making a Makefile (learn how to make them :-]) then, has to be in the same directory editing your source file with vim then you'd just have to hit escape then colon (:) and type make, after that you can type ":make run" (if you've made your Makefile well). --- Wei Weng [EMAIL PROTECTED] wrote: You can always use shell command from emacs. (is it M-x ! command_name?) Say have two window open in one frame under emacs. One is for editing and another one is for the gcc thingy. I don't know if there is any emacs scripts for making your programming more convenience(sp?). I like the way it is. I just open more windows. :) On Wed, 31 Mar 1999, Darius Blaszijk wrote: Hi all, Having my latest problems using DOS/WINDOWS, I decided to start programming under LINUX. I installed LINUX redhat 5.2 and bought myself the book L.A.D. I must say that I'm getting on quite well (I had to learn also how to program in C). But here is where my problems start. To do some programming I use for instance EMACS. When I'm done I exit EMACS and run GCC and then run the program to see if it does the thing I want it to do. This procedure is time consuming and not eficient. Is there any compiler/editor/debugger-package anvailable from the internet? Or am I missing something here? I've noticed that MC has an edit feature which shows source code using different colours. I find this very helpfull. Thanks a lot, Darius Blaszijk Get Your Private, Free Email at http://www.hotmail.com -- Wei Weng | idol of the week: Utada Hikaru| Part time oracle developer | CD of the week: first love | Full time J-ENT! NERD! (^^;; | o/~You will always be my love o/~ | -- _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
Re:
Use vi. It has syntax hilighting --- Henk Jan Barendregt [EMAIL PROTECTED] wrote: Darius Blaszijk wrote: Is there any compiler/editor/debugger-package anvailable from the internet? Or am I missing something here? I've noticed that MC has an edit feature which shows source code using different colours. I find this very helpfull. You can use wpe or xwpe for this. When you have bought the the RedHat box with book etc. Then you alse have the application cdrom with Code Crusader on it. Henk Jan _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
Re: your mail
go out to www.mamma.com and search for "ddd" It should be on ftp.lame.org, also. ddd uses gdb, and requires X windows. It provides superior source level debugging. you may also use xxgdb, or simply gdb to debug programs at the source level. you must compile and link with the -g option to do this. bug On Wed, 31 Mar 1999, Darius Blaszijk wrote: Hi all, Having my latest problems using DOS/WINDOWS, I decided to start programming under LINUX. I installed LINUX redhat 5.2 and bought myself the book L.A.D. I must say that I'm getting on quite well (I had to learn also how to program in C). But here is where my problems start. To do some programming I use for instance EMACS. When I'm done I exit EMACS and run GCC and then run the program to see if it does the thing I want it to do. This procedure is time consuming and not eficient. Is there any compiler/editor/debugger-package anvailable from the internet? Or am I missing something here? I've noticed that MC has an edit feature which shows source code using different colours. I find this very helpfull. Thanks a lot, Darius Blaszijk Get Your Private, Free Email at http://www.hotmail.com
Re:
Try vi, g++, and gdb Darius Blaszijk wrote: Is there any compiler/editor/debugger-package anvailable from the internet? Or am I missing something here? I've noticed that MC has an edit feature which shows source code using different colours. I find this very helpfull. You can use wpe or xwpe for this. When you have bought the the RedHat box with book etc. Then you alse have the application cdrom with Code Crusader on it. Henk Jan
Re: Type casting with malloc()
On Thu, 1 Apr 1999, holotko wrote: # My question. Do I really need to add the type cast (ObjectType *) # before the call to malloc() ? no. but gcc will warn you, if you use -Wall, about it. Doesn't do any harm leaving it in and if you miss it out gcc will add it in itself. Technically you need it because malloc returns memory cast to void *, which your data structures aren't. Makes your code more readable if you include it though. -- +++ If at first you don't succeed, you must be a programmer +++ [EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit
Re: Hmm ...
When a is 0. --- Joshua W. H. Steiner - [EMAIL PROTECTED] - http://joschi.base.org "Right now I am having amnesia and deja vu at the same time. I think I have forgotten this before." -Steven Wright I've got this from a website : Suppose you write this int foo (a) { if (a) return(1); } /* buggy, because sometimes no value is returned */ When does foo return no value ? - De Messemaeker Johan Research Development HEMMIS n.v. Koning LeopoldIII-laan 2, 8500 Kortrijk Tel.: 32 (0)56/37.26.37 Fax: 32 (0)56/37.23.24 Current Project : VMM Aalst
Re: your mail
You can always use shell command from emacs. (is it M-x ! command_name?) Say have two window open in one frame under emacs. One is for editing and another one is for the gcc thingy. I don't know if there is any emacs scripts for making your programming more convenience(sp?). I like the way it is. I just open more windows. :) On Wed, 31 Mar 1999, Darius Blaszijk wrote: Hi all, Having my latest problems using DOS/WINDOWS, I decided to start programming under LINUX. I installed LINUX redhat 5.2 and bought myself the book L.A.D. I must say that I'm getting on quite well (I had to learn also how to program in C). But here is where my problems start. To do some programming I use for instance EMACS. When I'm done I exit EMACS and run GCC and then run the program to see if it does the thing I want it to do. This procedure is time consuming and not eficient. Is there any compiler/editor/debugger-package anvailable from the internet? Or am I missing something here? I've noticed that MC has an edit feature which shows source code using different colours. I find this very helpfull. Thanks a lot, Darius Blaszijk Get Your Private, Free Email at http://www.hotmail.com -- Wei Weng | idol of the week: Utada Hikaru| Part time oracle developer | CD of the week: first love| Full time J-ENT! NERD! (^^;; | o/~You will always be my love o/~ | --
Re: your mail
This question just recently went across the linux-newbie list. I personally just tried out Code Crusader, which is quite nice: http://www.cco.caltech.edu/~jafl/jcc/ below is a response from the newbie list. --- Joshua W. H. Steiner - [EMAIL PROTECTED] - http://joschi.base.org "Sit with a pretty girl for an hour, and it seems like a minute. That's Relativity. " - Einstein From [EMAIL PROTECTED] Wed Mar 31 20:07:06 1999 Date: Wed, 31 Mar 1999 12:14:04 -0500 (EST) From: Kervin [EMAIL PROTECTED] To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: Visual X C++ Gtk+ and Glib (kinda like linux equiv. of MFC) http://www.gtk.org Glade (Ongoing project for a visual GUI builder for gtk+, new release just out today) http://glade.pn.org Gide (IDE for gtk) http://gide.pn.org the gide and glade sites seem to be down today. But you can get info on these and other programming tools if you search freshmeat, http://freshmeat.net.
Re: filecopy
first man open #include errno.h if ((in = open(source, O_RDONLY)) == -1) { perror("open"); /* should print reason */ exit(1); } --- [EMAIL PROTECTED] wrote: I use this code to copy a file : int copy_file(char *source, char *dest) { char c; int in, out; in = open(source, O_RDONLY); out = open(dest, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR); while(read(in, c, 1) == 1) write(out, c, 1); } I'd like to add a check for looking if the file is copied (no empty disk and such). What is the best way to do this ? - De Messemaeker Johan Research Development HEMMIS n.v. Koning LeopoldIII-laan 2, 8500 Kortrijk Tel.: 32 (0)56/37.26.37 Fax: 32 (0)56/37.23.24 Current Project : VMM Aalst _ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com
Re: strtok()
maybe it's just me, but i find this funny... (from the strtok() manpage) BUGS Never use this function. it's a fairly big bug! :) i expect there are similar things stuck to nuclear warheads (Warning! This device is hazardous to most forms of life, do not use). where is this? It's not in my manpage.
RE: strtok()
For those who don't know, strtok() is listed as a "don't use this function" in most documentation because it modifies the input string. Horribly. After using strtok() the original string is no longer usable because strtok() inserts NULL terminators into the original string at the end of each token. Another problem with it is that you know neither how many nor what type of separator was used between tokens, and there is no way of finding out because at least one of them was replaced by a NULL. A useful function, but very dangerous because the input is destroyed. ~Patrick maybe it's just me, but i find this funny... (from the strtok() manpage) BUGS Never use this function. it's a fairly big bug! :) i expect there are similar things stuck to nuclear warheads (Warning! This device is hazardous to most forms of life, do not use). where is this? It's not in my manpage.
Re: strtok()
strtok() uses a global to store its intermediate results. meaning that you can get unexpected results if several parts of your program use it. On Mon, 29 Mar 1999, Joseph Keen wrote: maybe it's just me, but i find this funny... (from the strtok() manpage) BUGS Never use this function. it's a fairly big bug! :) i expect there are similar things stuck to nuclear warheads (Warning! This device is hazardous to most forms of life, do not use). where is this? It's not in my manpage.
Re: strtok()
On Mon, 29 Mar 1999, Bug Hunter wrote: # # strtok() uses a global to store its intermediate results. meaning that # you can get unexpected results if several parts of your program use it. # it uses a local static variable actually. and it is very destructive, but if you make a copy of the string you're mangling then it's ok. how efficient are the string library routines? if my program does lots of strcmp()s and strcat()s etc will it be slower than if i was to write my own versions? -- +++ If at first you don't succeed, you must be a programmer +++ [EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit
Re: recv
It IS slow and inefficient to read 1 byte at a time. Read the recv man page for some other ideas. James wrote: is it really inefficient and slow to recv stuff from a socket 1 byte at a time? my program reads data from a socket 1 byte at a time, checking if the character read is a newline, if it isn't then the char is copied into a char array, otherwise the recv stops and something is done with the array. then the whole thing is repeated for the next line... etc. basically i want to be able to read strings of varying length from a socket, stopping when a newline is found. -- +++ If at first you don't succeed, you must be a programmer +++ [EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit
Re: poniter problem
Amol Mohite wrote: So when gcc pads it to 8 bytes, can we say for sure that next allocation might be at 8byte boundary ? No. You can be sure that it will satisfy any CPU-imposed alignment requirements, but that's all. -- Glynn Clements [EMAIL PROTECTED]
Re: timing functions?
Of course, shortly after I sent out my question to the list i got a lead which answered it for me. The only problem is that the "while( blockage);" is really ugly. Does anyone have any other suggestions of how to get around this? --- this sets up the interrupt handler for when you get an alarm. // initialization code { itimerval interval, old; signal( SIG_ALRM, unblock ); // this says how long to wait before starting the interval timer and // call the signal handler your_func_ptr interval.it_value.tv_sec = 0; interval.it_value.tv_usec = 2; // this says how frequently to call your_func_ptr interval.it_interval.tv_sec = 0; interval.it_interval.tv_usec = 2; setitimer( ITIMER_REAL, interval, old ); } // global stuff int blockage = 1; // in main { // your loop { // waits till the blockage is set to 0 // it wasts a lot of processor time but works easy while( blockage ); blockage = 1; // do something } } void unblock( ) { // clears the blockage and the while loop stops spinning blockage = 0; } --- Joshua W. H. Steiner - [EMAIL PROTECTED] - http://joschi.base.org If you think the problem is bad now, just wait until we've solved it. -Arthur Kasspe
Re: poniter problem
Hi! So when gcc pads it to 8 bytes, can we say for sure that next allocation might be at 8byte boundary ?
Re: poniter problem
Thanks I meant something like : *i = ((int *)c++); I guess this will work like doing (int *)++c. Sorry i meesd the brackets. will be more clear next time. Thank anyway.
Re: poniter problem
Amol Mohite wrote: say I have a char *c pointing to an array of 10 bytes. When i do (int *)c++ (increment before typecast -- forget the brackets for nw), and equate it t an int *i then *i will return 2nd to fifth bytes as integer. Is this correct ? No. `(int *)++c' or `(int *)(c+1)' would do that. `(int *)c++' stores the result before the increment occurs. And supose the typecase is beore the incerenent like so : ((int *)c)++ then *i will return 5th to 8th byes. is this correct ? ++((int *)c) will do that, but again `((int *)c)++' stores the result before the increment occurs. aslo how is exception handling implemented ? Does the processor have exception registers ? What sort of exception? Hardware exceptions (e.g. segfault) result in the processor jumping to a defined location. The details depend upon the particular type of processor. Also if I have allocated a struct liek : struct { int i; char b; }str; which is obviously 5 butes large. 1. The ANSI standard doesn't specify that `sizeof(int) == 4', so you shouldn't assume that it is. If you want an integer of a specific size, use the types from sys/types.h, e.g. int32_t. 2. It's 8 actually bytes on x86 using gcc. The structure is padded to a whole number of words. If you wanted to pack the structure, use: struct { int i; char b; } __attribute__ ((packed)) str; [NB: this is a gcc extension.] -- Glynn Clements [EMAIL PROTECTED]
Re: ???
James wrote: # will allocate space for a `char *', but it will point to some random # memory location. The result of using dbQuery as the first argument to # sprintf() will be undetermined. The one thing of which you can be sure # is that it will write to some memory which it shouldn't be writing to. about this... if one of my programs goes a bit mad and tries to write to something it shouldn't, does the memory write actually take place? or does Linux realise before and kill the process? It depends upon whether the memory is writable. If it isn't, attempting to write to it will cause a segfault. it creates a page fault because the memory wanted won't currently be in physical ram, Linux would go and fetch this page (if it exists), realise that the process doesn't have rights to access this page and send a SIGSEGV to the process. process then drops dead, creates a corefile and the user goes 'huh?... oh, missed the flipping in my scanf' [is that right?] The segfault would occur regardless of whether the page was present in physical RAM. Resident pages can be read-only. -- Glynn Clements [EMAIL PROTECTED]
Re: mkdir();
[EMAIL PROTECTED] wrote: The syntax for mkdir is : #include sys/mode.h #include sys/stat.h int mkdir (Path, Mode) const char *Path; mode_t Mode; I don't understand the mode_t structure. Can somebody mail me an example of how to use this function in a C-program ? mode_t is an integral type. You would typically use either a octal literals (e.g. 0755) or use the macros from sys/stat.h, e.g. S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH -- Glynn Clements [EMAIL PROTECTED]
Re: poniter problem
On Fri, 26 Mar 1999, Amol Mohite wrote: # say I have a char *c pointing to an array of 10 bytes. you mean: char myarray[10], *c; c = myarray; # When i do (int *)c++ (increment before typecast -- forget the brackets for # nw), and equate it t an int *i then please re-read what you type. this is full of typos and makes it really difficult to read. Also include example code as it makes it more clear. (int *)c++; doesn't do much except make c point at myarray[1] and return the value typecast as an int (thus returning the character's ascii code). # *i will return 2nd to fifth bytes as integer. Is this correct ? no, first make i point to the array. typecasting in that way doesn't convert the types of the elements in that array. To get the 2nd - 5th bytes (elements) as integers you'd have to: int cnt; for (cnt = 1; cnt 5; cnt++) printf ("%d\n", (int *)(c+cnt)); /* you have to do something with */ /* the typecast variables */ except why bother with pointers to array elements? for (cnt = 1; cnt 5; cnt++) printf ("%d\n", (int *)myarray[cnt]); # And supose the typecase is beore the incerenent like so : # ((int *)c)++ then *i will return 5th to 8th byes. is this correct ? no. that would cast c to an integer and then return the next one, which is of type char. # aslo how is exception handling implemented ? Does the processor have # exception registers ? what do you mean by exceptions? things like running out of memory and opening non-existant files, etc? to deal with these the functions that do the file i/o, memory allocation, whatever. return values that you check. # Also if I have allocated a struct liek : # # struct { # int i; # char b; # }str; # # which is obviously 5 butes large. not always. it will be sizeof (int) + sizeof (char) which on my machine (P233) is 5 bytes. Someone running a Sun or Alpha may have different sized variables. # Than whenre will the proceessor allocate the next bit of memory ? # Directly after the char b byte? it doesn't matter where it goes. All you need to know, as a C programmer, is that you have some struct called str which contains an integer and a character. Do you own a good C book? (the Kernighan Ritchie ANSI C Programming Book is a good one. Ones that mention Turbo C, or other DOS things, aren't - for Linux programming that is) -- +++ If at first you don't succeed, you must be a programmer +++ [EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit
Re: container class ?
On Fri, 26 Mar 1999, Chetan Sakhardande wrote: # Also in unix, how do i set an alarm with timer less than i sec? use usleep(). -- +++ If at first you don't succeed, you must be a programmer +++ [EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit
Re: mkdir();
The mode_t structure holds the permissions that you want to set on *Path. Take a look at the mkdir(2) and the chmod(2) man pages for more info. The syntax for mkdir is : #include sys/mode.h #include sys/stat.h int mkdir (Path, Mode) const char *Path; mode_t Mode; I don't understand the mode_t structure. Can somebody mail me an example of how to use this function in a C-program ? Thx and greetings - De Messemaeker Johan Research Development HEMMIS n.v. Koning LeopoldIII-laan 2, 8500 Kortrijk Tel.: 32 (0)56/37.26.37 Fax: 32 (0)56/37.23.24 Current Project : VMM Aalst
Re: container class ?
Chetan Sakhardande wrote: Also in unix, how do i set an alarm with timer less than i sec? setitimer() has up to microsecond resolution (depending upon what the OS supports). -- Glynn Clements [EMAIL PROTECTED]
Re: ???
On Mon, 22 Mar 1999, Glynn Clements wrote: # will allocate space for a `char *', but it will point to some random # memory location. The result of using dbQuery as the first argument to # sprintf() will be undetermined. The one thing of which you can be sure # is that it will write to some memory which it shouldn't be writing to. about this... if one of my programs goes a bit mad and tries to write to something it shouldn't, does the memory write actually take place? or does Linux realise before and kill the process? it creates a page fault because the memory wanted won't currently be in physical ram, Linux would go and fetch this page (if it exists), realise that the process doesn't have rights to access this page and send a SIGSEGV to the process. process then drops dead, creates a corefile and the user goes 'huh?... oh, missed the flipping in my scanf' [is that right?] -- +++ If at first you don't succeed, you must be a programmer +++ [EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit
Re: a program to read one's mailbox?
"Hossein S. Zadeh" wrote: Hi gurus, I have a unix (Linux) box with tens of users on it. The management has decided to move email to Groupwise (Novell). I was asked to look into possibility of sending current (saved) emails of users on the Unix box to their new email address. I have a sound background in C and C++, but I have never written a program to interact with mailboxes. Is it possible to have a small(ish) C program reading each mailbox, separate messages, and email them (one by one) to another address? Thanks, Hossein Not necessary. If you are using the standard UNIX mail tools, your mailbox is just a big text file. You can easily parse it with sed or perl to do what you need.
Re: a program to read one's mailbox?
On Tue, 23 Mar 1999, Scott Wegener wrote: Why not just setup a .forward, an alias or use procmail? You should be able to get some info on the .forward file and aliases by manning aliases and sendmail, or do a web search for the procmail home. (HINT: Using aliases or a .forward's a bit easier IMHO) Dear Scott, I need to keep receiving (and storing) emails for another couple of weeks. Then I moved them all to the new system over a weekend. What you suggested only affects emails coming from now on. I want to process whatever mail they already got (as well as the new incoming mails). Hossein
[SOLVED--SUMMARY] Re: a program to read one's mailbox?
On Mon, 22 Mar 1999, David Rysdam wrote: "Hossein S. Zadeh" wrote: Hi gurus, I have a unix (Linux) box with tens of users on it. The management has decided to move email to Groupwise (Novell). Thanks to everyone who responded. This is what I finally ended up stitching together: == #!/bin/sh cd /var/spool/mail for i in `ls [eE]*` do echo "Processing mailbox of: " echo $i echo "\n" cat $i | tail -n +12 | \ sed -e 's/^To: $i@old_machine/To: $i@new_machine/g' | \ formail -s /usr/bin/mail $i@new_machine done == I am not sure if the "sed" part is needed at all (or if it is correct for that matter). Some of the command line switches *might* be different from Linux versions. I wrote the above for Digital Unix. cheers, Hossein
Re: A NULL pointer that changes back after function call
Since ur chanhging the ptr, sned its address to the fucntion.
Re: modular programs
Check out "Linux device drivers" by Alessandro Rubini (ISBN 1-56592-292-1) The whole book is about writing modules for linux. But I don't get what's new about your idea - you can already load a lot of linux functional stuff with modules (by kerneld or the command line). - Etay Meiri [EMAIL PROTECTED] Linux is for people who know, and windows is for people who don't know, it's as simple as that. - On Sun, 14 Mar 1999, James wrote: i have what may turn out to be a nice idea but very hard to implement... i'm going to write a program and what i'd like is to have a kernel that takes care of memory management and other boring stuff and then have separate modules/plugins that actually do things (so there could be a networking module which handled all networking functions, a sound module which handled sound... etc). Sort of like the kernel and plugins for gimp/premiere/photoshop/ whatever. the question being... how? (cos somehow the kernel would need to know what is in each module without having that info hard coded into it) i've read the Linux Kernel Guide and it says the kernel modifies the addresses of it's modules so they can find the kernel's functions which seems nice and complex. -- [EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit
Re: Passing by reference in C++
"Andrew Bell [4036]" wrote: On Sun, Mar 14, 1999 at 05:12:13AM +, Glynn Clements wrote: holotko wrote: In C++ when passing values to a function we can pass values by "reference" like so: int foo(int int); // prototype for foo() main() { int x = 10; int y = 20; int result; result = foo(x, y); // The values of x and y passed to } And foo() defined as: int foo(int a, int b) { int value; ... return value; } One possible advantage to passing values this way is that in addition to returning a value to main() side effects are produced,i.e. if foo() modifies a or b the change will be reflected in the values of x or y in main, if such effects are desired. Pretty much the same effect can be easilly acheived via passing arguments as pointers (which is how I normally go about such a thing). My main 2 questions are: 1) What is the overall advantage of passing arguments this way (by reference), as oppsoed to using pointers , and, None. The above code is equivalent to having `foo' declared as int foo(int* a, int* b); and using `*a' and `*b' in the body. C++ references are merely `syntactic sugar' for using pointers. Personally I dislike this feature, as it makes it harder to see what is really going on. Isn't there at least one distinction? I don't have my C++ references handy (in fact they're on a remote island in South-Western Canada..), but passing by reference always meant that the object referred to by the reference existed. Pointers could be NULL (ie. point to NULL or invalid memory), but references needed to refer to instantiated objects of their type. Anyhow, it really is stupid to have both. Either pass EVERYTHING by reference and include a NULL object (that other objects inherit from), or do it the C way. Andrew Bell [EMAIL PROTECTED] Personally I think I prefer the overall versatility of pointers, even though they can be dangerous and can sometimes lead to fatal errors. My only problem with pointers is that sometimes I tend to overuse them, or at least I have been told that I do. Perhaps the "passing by reference" idea was an attempt to make C++ safer than C, in the sense that one can pass by reference under certain circumstances and avoid pointers and the potential problems which accompany them, unlike Java, which eliminated the pointer entirely. -- email: [EMAIL PROTECTED] Local mailserver landreau.ruffe.edu , remote ns.computer.net begin:vcard n:Holotko;John x-mozilla-html:FALSE org:MicroService Co. adr:;; version:2.1 email;internet:[EMAIL PROTECTED] title:Programmer note;quoted-printable:Unix, Systems Programming, Applications, =0D=0ASoftware Develpment, Sytems Administration. x-mozilla-cpt:;0 fn:John Holotko end:vcard
Re: ???
This allocates precisely one byte of data for dbQuery. Try char dbQuery[1024]; I replied to this mail too, but then I used char *dbQuery instead. What's the difference anyway? Torbjørn
Re: ???
On Mon, 22 Mar 1999 [EMAIL PROTECTED] wrote: But the output is : INSERT INTO w_deelmonster_im (dlmim_id, pntim_id, lab_id, dat_monstername, zendvlag, geannuleerd) SELECT eerd) SELECT m.dlmim_id If you declare dbQuery with char *dbQuery; instead of char dbQuery[] = ""; it works fine with me. With this modification I get the following output: INSERT INTO w_deelmonster_im (dlmim_id, pntim_id, lab_id, dat_monstername, zendvlag, geannuleerd) SELECT deelmonster_im.dlmim_id This should be right, but I can't explain it.. Glynn?? :) Torbjørn
Re: ???
Torbjørn Kristoffersen wrote: But the output is : INSERT INTO w_deelmonster_im (dlmim_id, pntim_id, lab_id, dat_monstername, zendvlag, geannuleerd) SELECT eerd) SELECT m.dlmim_id If you declare dbQuery with char *dbQuery; instead of char dbQuery[] = ""; it works fine with me. I don't think so. char *dbQuery; will allocate space for a `char *', but it will point to some random memory location. The result of using dbQuery as the first argument to sprintf() will be undetermined. The one thing of which you can be sure is that it will write to some memory which it shouldn't be writing to. Correct solutions include char dbQuery[SIZE]; or char *dbQuery = alloca(SIZE); or char *dbQuery = malloc(SIZE); or even char buff[SIZE]; char *dbQuery = buff; where SIZE is larger than the length of the string which sprintf() will generate. If you don't know how large the argument strings to sprintf() are, then either use snprintf() (which will truncate the result to the specified size), or specify format widths for the %s conversions, e.g. sprintf(dbQuery, "%100s%100s%100s%100s%100s%100s", ...); -- Glynn Clements [EMAIL PROTECTED]
Re: ???
On Mon, 22 Mar 1999, [ISO-8859-1] Torbjørn Kristoffersen wrote: This allocates precisely one byte of data for dbQuery. Try char dbQuery[1024]; I replied to this mail too, but then I used char *dbQuery instead. What's the difference anyway? Hi there, I think "char foo[n];" allocates the memory for foo; but "char *foo" creates the pointer with no memory allocated. You need to have a "malloc" (or "new" in C++) to get the memory actually allocated. Hossein
Re: cdrom_msf and cdrom_ti question
On Sun, 21 Mar 1999, Glynn Clements wrote: # I'm using struct cdrom_ti to play audio tracks, but when I try to play # the last track (this fails on every cd) it wont't play. # Every track but the last track works, isn't that weird? # One of my ideas is that maybe it has something to do with my use of # 'ti' instead of 'msf'? # # Are you trying to specify the start of a non-existent track as the end # position? isn't the very last track on a cd the lead-out track (a sort of "This is the End, you may stop now") which can't be played? -- +++ Beware of programmers who carry screwdrivers +++ [EMAIL PROTECTED] http://www.users.globalnet.co.uk/~kermit
Re: A NULL pointer that changes back after function call
Are you sure you passed the pointer's address but not the value of the pointer? -- Wei Weng | idol of the week: Utada Hikaru| Part time oracle developer | CD of the week: first love| Full time J-ENT! NERD! (^^;; | o/~You will always be my love o/~ | --
Re: learning ioctl()
Torbjxrn Kristoffersen wrote: I'm trying to make a program that simply ejects the CD-ROM. The reason why is that I'd like to learn more about the ioctl() call. Maybe I've misunderstood everything, but here's my code which doesn't work: FILE *fd = fopen("/dev/cdrom", "w"); The first argument to ioctl() must be a descriptor (an integer), as returned from open(), not an ANSI stream (`FILE *'). Also, trying to open /dev/cdrom for writing is likely to fail. int x; ioctl (fd, CDROMEJECT, x); (I'm not really sure why I'm using 'x', but I saw it being used in another example and I saw that ioctl() took a third argument also) The CDROMEJECT ioctl() doesn't use the third argument, so you can just pass zero. The following program works fine for me. -- Glynn Clements [EMAIL PROTECTED] #include unistd.h #include fcntl.h #include sys/ioctl.h #include linux/cdrom.h #include stdio.h int main(void) { int fd = open("/dev/cdrom", O_RDONLY); if (fd 0) { perror("open(\"/dev/cdrom\") failed"); return 1; } if (ioctl(fd, CDROMEJECT, 0) 0) { perror("ioctl(CDROMEJECT) failed"); return 1; } return 0; }