Unaligned access error
This message is output to the screen after my void function ends and before main regains control. Unaligned access pid=22768 p5.x va=0x11a1a pc=0x3ff80199120 ra=0x3ff800d4544 inst=0xa622fff8 Can anyone clue me in on what is going on in general? (ie layman's terms for Unaligned Access) I'm using classes with 'g++ -Wall' in my makefile for all. p5.x is my executable. I also get a nice little segmentation fault after a couple iterations of this (each with slightly different hex addresses). Thank you Best Regards, * Dan Jue, CMSC UMCP *Linux '99 * * * We Will Add Your Uniqueness To Our Own *
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]
compiling
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. Darius Blaszijk
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