|
code:
|
# ? Feb 26, 2009 20:41 |
|
|
# ? Apr 24, 2024 21:46 |
|
I am trying to define some global error handling functions, with declaration and definition in different files. Visual Studio is fine with this code, but gcc gives me warning "warning: 'function name' declared 'static' but never defined." Can someone tell me exactly what I'm doing wrong?code:
|
# ? Mar 2, 2009 07:01 |
|
Chuu posted:I am trying to define some global error handling functions, with declaration and definition in different files. Visual Studio is fine with this code, but gcc gives me warning "warning: 'function name' declared 'static' but never defined." Can someone tell me exactly what I'm doing wrong? Static functions don't have visibility outside of their compile units, meaning the linker doesn't (or at least shouldn't) see static functions that aren't defined in the compile unit. In other words, if you want to use a function in one .cpp file that is defined in another then don't mark it static.
|
# ? Mar 2, 2009 07:08 |
|
What flags do I pass to gcc to get it to compile sparc () assembly into a sparc binary on an intel machine?
|
# ? Mar 2, 2009 07:12 |
|
Contero posted:What flags do I pass to gcc to get it to compile sparc () assembly into a sparc binary on an intel machine? Stock GCC can't cross-compile like this, you need to build GCC specially as a cross compiler.
|
# ? Mar 2, 2009 07:40 |
|
ehnus posted:Static functions don't have visibility outside of their compile units, meaning the linker doesn't (or at least shouldn't) see static functions that aren't defined in the compile unit. In other words, if you want to use a function in one .cpp file that is defined in another then don't mark it static. Ugh, ok. The reason I am trying to do it like this is that this error handling code pretty much is included in every single file in the project, and the error handling code itself reaches tendrils into said code quite a bit. I need the "wall" between declaration and implementation to prevent an absolute ton of circular dependencies. I don't really have the freedom to change the code that links to the error function. Is there any way around this problem if I wanted to keep it as static functions without completely forward declaring entire class interfaces? For other reasons I really don't want to change the design to something like a singleton to solve this problem.
|
# ? Mar 2, 2009 09:04 |
|
Chuu posted:Ugh, ok. The reason I am trying to do it like this is that this error handling code pretty much is included in every single file in the project, and the error handling code itself reaches tendrils into said code quite a bit. I need the "wall" between declaration and implementation to prevent an absolute ton of circular dependencies. I don't understand. Why can't you just get rid of the static keyword and make it a global function? You don't have to make it a method of some class.
|
# ? Mar 2, 2009 09:07 |
|
Chuu, the key point that you're missing here is that, for source compatibility with C, static means something different on members and non-members. On members, it means (roughly) "this belongs to the class, not to instances of the class"; on non-members, it means "this belongs to this translation unit and cannot be accessed from a different module". Everything declared outside of a class is "static" in the sense of not being attached to an instance of some class. Yes, this is needlessly confusing; blame C.
|
# ? Mar 2, 2009 09:41 |
|
rjmccall posted:Chuu, the key point that you're missing here is that, for source compatibility with C, static means something different on members and non-members. On members, it means (roughly) "this belongs to the class, not to instances of the class"; on non-members, it means "this belongs to this translation unit and cannot be accessed from a different module". Everything declared outside of a class is "static" in the sense of not being attached to an instance of some class. Yes, this is needlessly confusing; blame C. Actually blame Bjarne Stroustroup for reusing a keyword in a rather unintuitive fashion
|
# ? Mar 2, 2009 09:57 |
|
Ok, thanks for the clarification. Coming from Java the fifty billion uses of 'static' is incredibly confusing.
|
# ? Mar 2, 2009 15:35 |
|
I have little to no idea of what I'm doing here so please forgive me if the answer is obvious. I tried googling around but to no avail. I have this C/C++ source for macos x that compiles to a static library just fine. I need that library to be a shared library. What do I do ? Is it "easy enough" and only involves tweaking the makefile or does it require extensive modification of the source ? For those interested in a bit more background, libtcod is a library for roguelike development in C/C++. The wrapper for Python is based on ctypes which requires shared libraries, but only the static ones are available for mac. (I am not the developer, in case you were wondering).
|
# ? Mar 2, 2009 15:39 |
|
Chuu posted:Ok, thanks for the clarification. Coming from Java the fifty billion uses of 'static' is incredibly confusing.
|
# ? Mar 2, 2009 16:17 |
|
Mustach posted:I don't know why you'd assume that it works the same way as in Java and then blame C++ (instead of yourself) when you used it in a circumstance that doesn't exist in Java. I don't see anywhere in that quote I'm blaming C++
|
# ? Mar 2, 2009 17:01 |
|
Maybe I jumped to conclusions, but when people say "coming from X, the fifty billion uses of Y in Z is incredibly confusing," — when there's actually just three uses for Y — it comes across as blaming Z for their assumption being wrong.
Mustach fucked around with this message at 18:04 on Mar 2, 2009 |
# ? Mar 2, 2009 18:02 |
|
Why does the following code compile in C++ mode, but not in C?code:
|
# ? Mar 2, 2009 20:01 |
|
C89 demands that declarations be the first thing in a block.
|
# ? Mar 2, 2009 20:17 |
|
Avenging Dentist posted:C89 demands that declarations be the first thing in a block. Yeah, but GCC doesn't seem to care about that in general.
|
# ? Mar 2, 2009 21:59 |
|
I'm having a hard time figuring out where I should go with this assignment. I'm supposed to simulate a vending machine where there are a bunch of things worth a certain amount, and ultimately gives them the item and returns whatever cash they have left in the smallest possible amount of coins. For example, 35 cents remainder would return a quarter and a dime. If you don't have enough money to buy the item, it should say deposit more money or select a different product (I'm thinking here I should throw the user a choice, choosing to deposit money brings him a scanf where it'll add to the amount of money he put in, where the other choice he sees the menu again.) I'm just trying to figure out how I'd go about this. I was thinking a dowhile loop where it would print the menu, the user makes a selection and an action happens and after that my brain just goes I've got this so far but now I'm thinking I shouldn't use a do while for this http://pastebin.com/m638b3b65
|
# ? Mar 2, 2009 22:14 |
|
A do {} while () loop is just fine here. Loop structure should not be the major problem in this assignment. Talk to your TA if you're really blocking on this. Also, float cannot store hundredths with perfect precision; you should strongly consider representing currency using whole numbers of cents rather than fractional numbers of dollars.
|
# ? Mar 2, 2009 22:54 |
|
rjmccall posted:A do {} while () loop is just fine here. Loop structure should not be the major problem in this assignment. Talk to your TA if you're really blocking on this. I'm not sure how else to discern between what is a dollar or a penny if say the user puts in "1"
|
# ? Mar 2, 2009 23:12 |
|
Gvaz posted:I'm not sure how else to discern between what is a dollar or a penny if say the user puts in "1" You should definitely assume that the user is giving you dollar amounts (unless the assignment tells you otherwise); I'm just saying that internally, you will save yourself much grief if you represent (say) $3 as the integer 300 instead of the floating-point value 3.0. EDIT: and similarly, you would also print the numbers as dollar amounts; I'm just talking about the internal types that your program uses to store numbers. rjmccall fucked around with this message at 23:33 on Mar 2, 2009 |
# ? Mar 2, 2009 23:29 |
|
rjmccall posted:You should definitely assume that the user is giving you dollar amounts (unless the assignment tells you otherwise); I'm just saying that internally, you will save yourself much grief if you represent (say) $3 as the integer 300 instead of the floating-point value 3.0. It just says "must be capable of accepting any coins as well as dollar bills" but I'll try doing the numbers like that, inside the program.
|
# ? Mar 2, 2009 23:31 |
|
Gvaz posted:I'm not sure how else to discern between what is a dollar or a penny if say the user puts in "1" scanf() formats can help you here, something like "$%d.%d" could be useful.
|
# ? Mar 2, 2009 23:31 |
|
Otto Skorzeny posted:scanf() formats can help you here, something like "$%d.%d" could be useful. I'm not sure I can do that because it says "must be returned with the smallest possible amount of coins" instead of a straight value.
|
# ? Mar 2, 2009 23:33 |
|
Gvaz posted:I'm not sure I can do that because it says "must be returned with the smallest possible amount of coins" instead of a straight value. I'm talking about taking input re: how much money the user is 'paying'. Your algo for returning coins is unrelated.
|
# ? Mar 2, 2009 23:47 |
|
Gonna be working on some pretty complex stuff in C in the near future, thinking about doing some unit test coverage, what's the best unit testing framework for C?
|
# ? Mar 2, 2009 23:51 |
|
Is there some way to cause a previously defined function to give a compiler error when used? I would like to cause the OpenGL function glColor4f() to give an error, so I remember to use my own.
|
# ? Mar 3, 2009 00:55 |
|
Red Blaze posted:Is there some way to cause a previously defined function to give a compiler error when used? I would like to cause the OpenGL function glColor4f() to give an error, so I remember to use my own. You could define glColor4f as a macro that produces uncompilable garbage. I'm not sure if GCC lets you define parameterized macros as precompiler parameters but that would probably be the cleanest way to do it. Edit: -D'glColor4f(params)=DO_NOT_USE_THIS_FUNCTION=0;/*params*/' or whatever should work Painless fucked around with this message at 02:29 on Mar 3, 2009 |
# ? Mar 3, 2009 02:21 |
|
Painless posted:You could define glColor4f as a macro that produces uncompilable garbage. I'm not sure if GCC lets you define parameterized macros as precompiler parameters but that would probably be the cleanest way to do it. This works great. I will just use this macro so I know the context of the error. #define glColor4f(r,g,b,a) glColor4fDontUse(r*g*b*a)
|
# ? Mar 3, 2009 02:34 |
|
Visual Studio question: I am setting compile options for a single source file ("prime.cu" in this case). code:
|
# ? Mar 3, 2009 04:42 |
|
Red Blaze posted:This works great. I will just use this macro so I know the context of the error. Don't know the context of this, but something like #define glColor4f(r,g,b,a) glColor4fDontUse((r)*(g)*(b)*(a)) will be safer. Edit: Actually read the context, it would appear that you are not going for correctness . TheSpook fucked around with this message at 04:48 on Mar 3, 2009 |
# ? Mar 3, 2009 04:46 |
|
Red Blaze posted:This works great. I will just use this macro so I know the context of the error. Can't you just undefine it?
|
# ? Mar 3, 2009 04:46 |
|
Why are you even worrying about parameters?code:
|
# ? Mar 3, 2009 04:56 |
|
Ugg boots posted:Can't you just undefine it? No.
|
# ? Mar 3, 2009 05:02 |
|
Does anyone know if there is a free library that offers thread-local storage without the requirement that the thread was created in a particular way? I was looking at ACE's implementation of Thread-Local storage but it carries the requirement that the thread inherit from ACE_Task_Base.
|
# ? Mar 3, 2009 05:14 |
|
Bonus posted:Gonna be working on some pretty complex stuff in C in the near future, thinking about doing some unit test coverage, what's the best unit testing framework for C? I don't know about best, but CPPUnit is very mature and has served my needs on a very complicated project. Bonus points for the fact it has an XML outputter which with xlst translation means I can use its output to feed any CI tool that was build around junit/nunit. CPPUnit doesn't "plug into" your code like some Unit testing tools in other languages, you pretty much have a separate main and wrappers for all the classes you are testing.
|
# ? Mar 3, 2009 05:16 |
|
Chuu posted:Does anyone know if there is a free library that offers thread-local storage without the requirement that the thread was created in a particular way? Boost.Thread
|
# ? Mar 3, 2009 05:27 |
|
Chuu posted:I don't know about best, but CPPUnit is very mature and has served my needs on a very complicated project. Bonus points for the fact it has an XML outputter which with xlst translation means I can use its output to feed any CI tool that was build around junit/nunit. "C"
|
# ? Mar 3, 2009 05:34 |
|
ok go etc posted:I have this C/C++ source for macos x that compiles to a static library just fine. I need that library to be a shared library. What do I do ? Is it "easy enough" and only involves tweaking the makefile or does it require extensive modification of the source ? I think what you want to do is compile your library as a shared library rather than converting your existing static one. A command line something like code:
I shouldn't think source modification would be required.
|
# ? Mar 3, 2009 08:06 |
|
|
# ? Apr 24, 2024 21:46 |
|
That Turkey Story posted:No. Oh, I was thinking the original one was a macro defined outside of his project so he was stuck with it. My bad.
|
# ? Mar 3, 2009 09:45 |