(Latest update: Well, folks, this already becomes a holy war. I like the answer given by Ryan M below together with my response to him in the comments. At least, it works for me. So I suggest considering this question answered.)
Please see the https://stackoverflow.com/questions/68620580/passing-a-double-variable-to-the-kernels-cuda
Screenshot of the deleted question
Somebody closed this question with the reason "not reproducible or was caused by typos".
Well:
- It is reproducible since one can reproduce it easily, although the issue is fixed and resolved. But this is common for most Stack Overflow questions.
- This is not a typo, but a real error which beginners do very often just because it is a trap in format for printf: of course, it is counter-intuitive to have %d responsible for
int
instead of double while other types have some kind of the correspondence. 2.1. Of course, this is a childish error, but this is an error, not a typo when a developer just pressed the wrong button. This is what they do "intentionally".
At the same time, I agree that the question is not generic enough; it is worded for CUDA kernels while relating to pure C/C++.
Anyway, I see both the question and answer as beneficial for developers who may find them by search.
Any ideas why the question was closed with this reason?
Update based on the comments: Folks, I don't mind closing the question:
- Of course, it is an obvious duplicate since this is a very widespread case.
- Of course, it doesn't relate to CUDA at all, although relates to CUDA C as a subset of C, anyway, it would be nice to make it more generic, maybe putting it in Q&A format.
So, my concern is not closing, but the closing reason since in another situation it could lead to wrong closure.
Regarding the question and its wording, put yourself in the shoes of the author. He had a problem in CUDA C code and he had no idea at that moment what exactly caused the problem, so he provided the context. It is not his fault that real issue was narrower.
If the question was closed as a duplicate, that could be of great help, but "not reproducible or was caused by typos" is misleading and if anybody else in the same issue, this could be in their way to find the solution.
So my key concern at the moment: Please ignore the fact that the (1) question duplicates other questions, (2) this is a basic common knowledge, (3) it doesn't relate to CUDA.
Please pay attention to the closure reason. What stops users to close next time a unique, complex, CUDA-related (or other technology-related question) with the reason "not reproducible or was caused by typos" just because they see it like "hey, here is just one letter to replace"! as happened here?
This is my only concern here.
d
wheref
orlf
should have been used, I can see justification for closing as typo.%d
anddouble
— it really is mostly a question of 'not using the compiler facilities correctly'. Note that the mnemonic for%d
is decimal, and%o
is octal and%x
(or%X
) is hexadecimal, while%f
is for floating point (as opposed to one of the integer representations). You merely have to know (be taught) the correct mnemonics.printf
format specifiers to know the difference. The most likely response is "I don't know I just copied this from a tutorial and it doesn't work", because most askers today aren't interested in understanding, just making their code compile. Further, there is nothing that such a comment would add over a dupe close vote pointing to a question aboutprintf
format specifiers.