User Profile
Collapse
-
If I pass a pointer to a vector3, I get a pointer to a pointer, and I'm not sure it would be efficient to double dereference. I never return a vector3 in the first place. I was merely wondering if it passed a float pointer to a function rather than allocate/occupy/magically create 3 float values in an array for local use, like it would passing a structure by value. I know how a stack works. -
Did a quick test in GDB, and it appears to pass it as a float pointer. I'll leave this as a reference for others, though it may be implementation dependent.Leave a comment:
-
Passing arrays to a function
Say I have a couple functions like so:
Would that be treated the same as:Code:typedef float vector[3]; void foo(vector t){ /* Do whatever */ } void bar(void){ vector v; foo(v); /* Rest of program */ }
...Code:typedef float vector[3]; void foo(float * t){ /* Do whatever */ } void -
Also consider whether or not your datatype is unsigned; it has an effect on the maximum size of your positive integer. That said, your string literal still contains a number larger than both signed and unsigned 32 bit integers can hold.Leave a comment:
-
Ectara replied to Currently doing development using C language, for final product, reduce code size?in CAlso, optimizations for your code can be enabled in many compilers to increase speed and often remove dead code, cutting down size.Leave a comment:
-
In C++, a string can be described as a class for handling an array of characters; for example, text. I can't quite remember how to compare strings in C++(I use C mostly), but I'm pretty sure there is an operator to test this defined in the class.
Global variables are variables defined outside of any function, and are available to all functions in that file. They are not freed until the end of the program, so their value will always be...Leave a comment:
-
No problem at all. Glad to help. I've done things like that before. Good luck on your assignment.Leave a comment:
-
FINALLY FOUND IT!
...Code:int main ( int argc, char** argv ) { //BEGIN_MAIN unsigned int mainCounter ; unsigned int i ; if ( argc != 2 ) { printf ("./read_instance instance_file\n"); return 0 ; } checklist= (unsigned int*) malloc ( instance.n * sizeof(unsigned int) ) ; optlist= (unsigned int*) malloc ( instance.n * sizeof(unsigned int) ) ;Leave a comment:
-
Oh, those were line numbers at the end of your last post.
Hm. That is strange. The program initially has the right answer, then changes to something completely wrong. I'll take a closer look at it right now.Leave a comment:
-
Well, with the lack of the real input file, I took some liberties from what the code appears to do, and made a test file:
4
1 20 1
2 40 4
3 70 15
4 20 8
15
As you can see, with a max weight of 15, picking the first two and the last one would come out to more value than picking the third, or any other combination.
The output:
ectara@Nemesis: ~$ g++ /home/ectara/Desktop/code/temp/read_instance.c ;...Leave a comment:
-
Can you provide a sample input file that is being used to test this?
And also, can you paste the output when executing this in Windows? I only run Linux on this machine.Leave a comment:
-
We need more information, such as a code snippet or output, to be able to help you.Leave a comment:
-
If you were to do so, you could start by outputting the number digit by digit, starting with the most significant in a loop. Keep in mind, floating point inaccuracies will occur. IIRC, float can accurately store 6 digits, and double accurately stores 15 digits, mantissa included. Anything outside of that, could be anything.Leave a comment:
-
Also, using the code tag would help others read it and provide help.Leave a comment:
-
If you are fine with macros, you could #define in one of your main headers to change fprintf and printf to functions that you name, and use the same argument list.
And Jon, I'm not sure of the protocol, but that probably should have gone in a PM.Leave a comment:
-
Hm. Well, it is working for now, and many other people use it with few complaints, so I guess I can make replacements for my old byte-by-byte I/O. Is there a more efficient way to buffer and swap the order of the bytes than what I did?Leave a comment:
-
Also, in the if statement on line 5, make sure you use the == operator for making comparisons, rather than the = assignment operator. It would give unexpected results otherwise.Leave a comment:
-
In the example, the pointer is not initialized, nor is it pointing to the address of the structer declared above it. Though, by your follow-up response, I assume that this isn't an actual code snippet from your project. But otherwise, yeah, lines 3 and 4 would do the same thing if the pointer pointed to the address of the structure.Leave a comment:
-
Something silly like recompiling the executable to fix a spelling error in a string literal, unrelated to the function or the file I/O, such as a welcome message that is printed directly without manipulation. All of a sudden, reading in what was once valid data, provides partially correct data, but some stack allocated variables come up empty or bizarre numbers. Boggles my mind how it is possible when I'm looking at a valid hexdump, and how it is...Leave a comment:
-
Also, I neglected to mention that the entire library is designed to operate in big endian, as seen in the function above that when it writes out for little endian, it writes each set of size bytes in reverse, while if big endian, it writes the bytes in order. I suppose I could do something like using a small buffer of size length to swap the bytes around and issue one fwrite() call per set. I was just curious if fwrite() really is as fickle as it...Leave a comment:
No activity results to display
Show More
Leave a comment: