Declaring function on another .c file makes float multiplication always be 0Unsuccessful fread() of int stored in binary file, segmentation faultMake a float only show two decimal placesWhy is “while (!feof(file))” always wrong?printf by given pointer and format string. Issue with floatsHow do I achieve the theoretical maximum of 4 FLOPs per cycle?Using structs in multiple filesC++ Truncating Floats in Function Return16bit Float Multiplication in CInitialize multiple arrays in function C programmingImplicit function declarations and linkageThis C function should always return false, but it doesn’t
LaTeX closing $ signs makes cursor jump
How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?
The use of multiple foreign keys on same column in SQL Server
What are the differences between the usage of 'it' and 'they'?
What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)
Can I ask the recruiters in my resume to put the reason why I am rejected?
Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)
Why not use SQL instead of GraphQL?
Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?
How could an uplifted falcon's brain work?
How does strength of boric acid solution increase in presence of salicylic acid?
How old can references or sources in a thesis be?
Why, historically, did Gödel think CH was false?
What are these boxed doors outside store fronts in New York?
Why doesn't H₄O²⁺ exist?
Show that if two triangles built on parallel lines, with equal bases have the same perimeter only if they are congruent.
Is this a crack on the carbon frame?
Which models of the Boeing 737 are still in production?
Font hinting is lost in Chrome-like browsers (for some languages )
What's the point of deactivating Num Lock on login screens?
Why do falling prices hurt debtors?
"to be prejudice towards/against someone" vs "to be prejudiced against/towards someone"
In Japanese, what’s the difference between “Tonari ni” (となりに) and “Tsugi” (つぎ)? When would you use one over the other?
"You are your self first supporter", a more proper way to say it
Declaring function on another .c file makes float multiplication always be 0
Unsuccessful fread() of int stored in binary file, segmentation faultMake a float only show two decimal placesWhy is “while (!feof(file))” always wrong?printf by given pointer and format string. Issue with floatsHow do I achieve the theoretical maximum of 4 FLOPs per cycle?Using structs in multiple filesC++ Truncating Floats in Function Return16bit Float Multiplication in CInitialize multiple arrays in function C programmingImplicit function declarations and linkageThis C function should always return false, but it doesn’t
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
If I define the function in the main, everything works fine. But if I define the function in another c file, this weir float multiplication problem happens: it gives 0 always.
example1/main.c:
int multiply_by_2(float scalar)
printf("result: %fn", scalar*2);
int main()
multiply_by_2(3);
example1/CMakeLists.txt
cmake_minimum_required(VERSION 2.6.0)
project(example C)
add_executable(example main.c)
Output:
result: 6.000000
example2/main.c:
int main()
multiply_by_2(3);
example2/a.c:
int multiply_by_2(float scalar)
printf("result: %fn", scalar*2);
example2/CMakeLists.txt:
cmake_minimum_required(VERSION 2.6.0)
project(example C)
add_executable(example main.c a.c)
Output:
result: 0.000000
c floating-point
add a comment |
If I define the function in the main, everything works fine. But if I define the function in another c file, this weir float multiplication problem happens: it gives 0 always.
example1/main.c:
int multiply_by_2(float scalar)
printf("result: %fn", scalar*2);
int main()
multiply_by_2(3);
example1/CMakeLists.txt
cmake_minimum_required(VERSION 2.6.0)
project(example C)
add_executable(example main.c)
Output:
result: 6.000000
example2/main.c:
int main()
multiply_by_2(3);
example2/a.c:
int multiply_by_2(float scalar)
printf("result: %fn", scalar*2);
example2/CMakeLists.txt:
cmake_minimum_required(VERSION 2.6.0)
project(example C)
add_executable(example main.c a.c)
Output:
result: 0.000000
c floating-point
You don't needcmake
for such a simple example
– Basile Starynkevitch
Mar 9 at 2:36
1
Clearly this doesn't compile, or at least shouldn't.printf()
isn't declared ina.c
, andmultiply_by_2()
isn't declared inmain.c
... show the full code.
– Havenard
Mar 9 at 3:07
add a comment |
If I define the function in the main, everything works fine. But if I define the function in another c file, this weir float multiplication problem happens: it gives 0 always.
example1/main.c:
int multiply_by_2(float scalar)
printf("result: %fn", scalar*2);
int main()
multiply_by_2(3);
example1/CMakeLists.txt
cmake_minimum_required(VERSION 2.6.0)
project(example C)
add_executable(example main.c)
Output:
result: 6.000000
example2/main.c:
int main()
multiply_by_2(3);
example2/a.c:
int multiply_by_2(float scalar)
printf("result: %fn", scalar*2);
example2/CMakeLists.txt:
cmake_minimum_required(VERSION 2.6.0)
project(example C)
add_executable(example main.c a.c)
Output:
result: 0.000000
c floating-point
If I define the function in the main, everything works fine. But if I define the function in another c file, this weir float multiplication problem happens: it gives 0 always.
example1/main.c:
int multiply_by_2(float scalar)
printf("result: %fn", scalar*2);
int main()
multiply_by_2(3);
example1/CMakeLists.txt
cmake_minimum_required(VERSION 2.6.0)
project(example C)
add_executable(example main.c)
Output:
result: 6.000000
example2/main.c:
int main()
multiply_by_2(3);
example2/a.c:
int multiply_by_2(float scalar)
printf("result: %fn", scalar*2);
example2/CMakeLists.txt:
cmake_minimum_required(VERSION 2.6.0)
project(example C)
add_executable(example main.c a.c)
Output:
result: 0.000000
c floating-point
c floating-point
asked Mar 9 at 2:28
Guerlando OCsGuerlando OCs
827
827
You don't needcmake
for such a simple example
– Basile Starynkevitch
Mar 9 at 2:36
1
Clearly this doesn't compile, or at least shouldn't.printf()
isn't declared ina.c
, andmultiply_by_2()
isn't declared inmain.c
... show the full code.
– Havenard
Mar 9 at 3:07
add a comment |
You don't needcmake
for such a simple example
– Basile Starynkevitch
Mar 9 at 2:36
1
Clearly this doesn't compile, or at least shouldn't.printf()
isn't declared ina.c
, andmultiply_by_2()
isn't declared inmain.c
... show the full code.
– Havenard
Mar 9 at 3:07
You don't need
cmake
for such a simple example– Basile Starynkevitch
Mar 9 at 2:36
You don't need
cmake
for such a simple example– Basile Starynkevitch
Mar 9 at 2:36
1
1
Clearly this doesn't compile, or at least shouldn't.
printf()
isn't declared in a.c
, and multiply_by_2()
isn't declared in main.c
... show the full code.– Havenard
Mar 9 at 3:07
Clearly this doesn't compile, or at least shouldn't.
printf()
isn't declared in a.c
, and multiply_by_2()
isn't declared in main.c
... show the full code.– Havenard
Mar 9 at 3:07
add a comment |
2 Answers
2
active
oldest
votes
int multiply_by_2(float scalar)
printf("result: %fn", scalar*2);
you have an int
returning function which does not return
any integer. This triggers undefined behavior (once you call that multiply_by_2
function elsewhere). Be scared, very bad things could happen (even outside of that multiply_by_2
function or outside of its caller).
Next time, compile with all warnings and debug info, so with gcc -Wall -Wextra -g
if using GCC. Improve your code to get no warnings.
Read also How to debug small programs.
If you use floating point numbers, be very cautious. They are difficult to understand and behave counter-intuitively (e.g. addition is not associative). Read http://floating-point-gui.de/ first.
If you have several translation units (e.g. source files such as a.c
and main.c
) you should in practice at least have some common header file and #include
it in every *.c
file. At a first approximation, your header file should declare all your [global] types and functions. And you'll need to configure your build automation tool (e.g. write your Makefile
) to take into account such dependencies: your header file should somehow be mentioned.
Read much more about C programming. See also some C reference site. Read the documentation of every function you are using (e.g. of printf)
You'll learn a lot by studying the source code of existing small free software programs (e.g. on github, gitlab, in a Linux distribution, etc).
3
you have an int returning function which does not return any integer. This is undefined behavior. No, this is not undefined behavior. The behavior is undefined when the value of the function call is used by the caller in this case. The code shown in example2 nowhere uses the value ofmultiply_by_2()
function call.
– H.S.
Mar 9 at 2:52
@H.S.: Huh. Learn something new every day. N1570, 5.9.1 Function definitions, item #12: "If the}
that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined."
– ShadowRanger
Mar 13 at 13:37
@ShadowRanger Of course and that what I wrote in my comment - The behavior is undefined when the value of the function call is used by the caller in this case. In this sentence by "in this case", I am referring the case where the function is suppose to return some value but the return statement is missing.
– H.S.
Mar 13 at 13:53
@H.S.: Yeah, I was thanking you for pointing that out and providing the associated reference. I was surprised, and looked it up for myself; figured I'd save others the effort. :-)
– ShadowRanger
Mar 13 at 14:38
add a comment |
The problem was that I should add a declaration of the functions in main.c, even though my compiler wouldn't warne me about it. With the declarations, all bugs are gone
1
I suspect turning up your warning level would get a warning output. Undeclared functions are kind of basic.
– ShadowRanger
Mar 9 at 2:31
2
Actually, you should have some common header file and include it everywhere. Copy & pasting the same declaration in several files is not scalable and should be avoided (unless perhaps your C source files are generated from something else; then the generator could duplicate declarations)
– Basile Starynkevitch
Mar 9 at 3:01
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073435%2fdeclaring-function-on-another-c-file-makes-float-multiplication-always-be-0%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
int multiply_by_2(float scalar)
printf("result: %fn", scalar*2);
you have an int
returning function which does not return
any integer. This triggers undefined behavior (once you call that multiply_by_2
function elsewhere). Be scared, very bad things could happen (even outside of that multiply_by_2
function or outside of its caller).
Next time, compile with all warnings and debug info, so with gcc -Wall -Wextra -g
if using GCC. Improve your code to get no warnings.
Read also How to debug small programs.
If you use floating point numbers, be very cautious. They are difficult to understand and behave counter-intuitively (e.g. addition is not associative). Read http://floating-point-gui.de/ first.
If you have several translation units (e.g. source files such as a.c
and main.c
) you should in practice at least have some common header file and #include
it in every *.c
file. At a first approximation, your header file should declare all your [global] types and functions. And you'll need to configure your build automation tool (e.g. write your Makefile
) to take into account such dependencies: your header file should somehow be mentioned.
Read much more about C programming. See also some C reference site. Read the documentation of every function you are using (e.g. of printf)
You'll learn a lot by studying the source code of existing small free software programs (e.g. on github, gitlab, in a Linux distribution, etc).
3
you have an int returning function which does not return any integer. This is undefined behavior. No, this is not undefined behavior. The behavior is undefined when the value of the function call is used by the caller in this case. The code shown in example2 nowhere uses the value ofmultiply_by_2()
function call.
– H.S.
Mar 9 at 2:52
@H.S.: Huh. Learn something new every day. N1570, 5.9.1 Function definitions, item #12: "If the}
that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined."
– ShadowRanger
Mar 13 at 13:37
@ShadowRanger Of course and that what I wrote in my comment - The behavior is undefined when the value of the function call is used by the caller in this case. In this sentence by "in this case", I am referring the case where the function is suppose to return some value but the return statement is missing.
– H.S.
Mar 13 at 13:53
@H.S.: Yeah, I was thanking you for pointing that out and providing the associated reference. I was surprised, and looked it up for myself; figured I'd save others the effort. :-)
– ShadowRanger
Mar 13 at 14:38
add a comment |
int multiply_by_2(float scalar)
printf("result: %fn", scalar*2);
you have an int
returning function which does not return
any integer. This triggers undefined behavior (once you call that multiply_by_2
function elsewhere). Be scared, very bad things could happen (even outside of that multiply_by_2
function or outside of its caller).
Next time, compile with all warnings and debug info, so with gcc -Wall -Wextra -g
if using GCC. Improve your code to get no warnings.
Read also How to debug small programs.
If you use floating point numbers, be very cautious. They are difficult to understand and behave counter-intuitively (e.g. addition is not associative). Read http://floating-point-gui.de/ first.
If you have several translation units (e.g. source files such as a.c
and main.c
) you should in practice at least have some common header file and #include
it in every *.c
file. At a first approximation, your header file should declare all your [global] types and functions. And you'll need to configure your build automation tool (e.g. write your Makefile
) to take into account such dependencies: your header file should somehow be mentioned.
Read much more about C programming. See also some C reference site. Read the documentation of every function you are using (e.g. of printf)
You'll learn a lot by studying the source code of existing small free software programs (e.g. on github, gitlab, in a Linux distribution, etc).
3
you have an int returning function which does not return any integer. This is undefined behavior. No, this is not undefined behavior. The behavior is undefined when the value of the function call is used by the caller in this case. The code shown in example2 nowhere uses the value ofmultiply_by_2()
function call.
– H.S.
Mar 9 at 2:52
@H.S.: Huh. Learn something new every day. N1570, 5.9.1 Function definitions, item #12: "If the}
that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined."
– ShadowRanger
Mar 13 at 13:37
@ShadowRanger Of course and that what I wrote in my comment - The behavior is undefined when the value of the function call is used by the caller in this case. In this sentence by "in this case", I am referring the case where the function is suppose to return some value but the return statement is missing.
– H.S.
Mar 13 at 13:53
@H.S.: Yeah, I was thanking you for pointing that out and providing the associated reference. I was surprised, and looked it up for myself; figured I'd save others the effort. :-)
– ShadowRanger
Mar 13 at 14:38
add a comment |
int multiply_by_2(float scalar)
printf("result: %fn", scalar*2);
you have an int
returning function which does not return
any integer. This triggers undefined behavior (once you call that multiply_by_2
function elsewhere). Be scared, very bad things could happen (even outside of that multiply_by_2
function or outside of its caller).
Next time, compile with all warnings and debug info, so with gcc -Wall -Wextra -g
if using GCC. Improve your code to get no warnings.
Read also How to debug small programs.
If you use floating point numbers, be very cautious. They are difficult to understand and behave counter-intuitively (e.g. addition is not associative). Read http://floating-point-gui.de/ first.
If you have several translation units (e.g. source files such as a.c
and main.c
) you should in practice at least have some common header file and #include
it in every *.c
file. At a first approximation, your header file should declare all your [global] types and functions. And you'll need to configure your build automation tool (e.g. write your Makefile
) to take into account such dependencies: your header file should somehow be mentioned.
Read much more about C programming. See also some C reference site. Read the documentation of every function you are using (e.g. of printf)
You'll learn a lot by studying the source code of existing small free software programs (e.g. on github, gitlab, in a Linux distribution, etc).
int multiply_by_2(float scalar)
printf("result: %fn", scalar*2);
you have an int
returning function which does not return
any integer. This triggers undefined behavior (once you call that multiply_by_2
function elsewhere). Be scared, very bad things could happen (even outside of that multiply_by_2
function or outside of its caller).
Next time, compile with all warnings and debug info, so with gcc -Wall -Wextra -g
if using GCC. Improve your code to get no warnings.
Read also How to debug small programs.
If you use floating point numbers, be very cautious. They are difficult to understand and behave counter-intuitively (e.g. addition is not associative). Read http://floating-point-gui.de/ first.
If you have several translation units (e.g. source files such as a.c
and main.c
) you should in practice at least have some common header file and #include
it in every *.c
file. At a first approximation, your header file should declare all your [global] types and functions. And you'll need to configure your build automation tool (e.g. write your Makefile
) to take into account such dependencies: your header file should somehow be mentioned.
Read much more about C programming. See also some C reference site. Read the documentation of every function you are using (e.g. of printf)
You'll learn a lot by studying the source code of existing small free software programs (e.g. on github, gitlab, in a Linux distribution, etc).
edited Mar 9 at 2:59
answered Mar 9 at 2:33
Basile StarynkevitchBasile Starynkevitch
180k13174375
180k13174375
3
you have an int returning function which does not return any integer. This is undefined behavior. No, this is not undefined behavior. The behavior is undefined when the value of the function call is used by the caller in this case. The code shown in example2 nowhere uses the value ofmultiply_by_2()
function call.
– H.S.
Mar 9 at 2:52
@H.S.: Huh. Learn something new every day. N1570, 5.9.1 Function definitions, item #12: "If the}
that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined."
– ShadowRanger
Mar 13 at 13:37
@ShadowRanger Of course and that what I wrote in my comment - The behavior is undefined when the value of the function call is used by the caller in this case. In this sentence by "in this case", I am referring the case where the function is suppose to return some value but the return statement is missing.
– H.S.
Mar 13 at 13:53
@H.S.: Yeah, I was thanking you for pointing that out and providing the associated reference. I was surprised, and looked it up for myself; figured I'd save others the effort. :-)
– ShadowRanger
Mar 13 at 14:38
add a comment |
3
you have an int returning function which does not return any integer. This is undefined behavior. No, this is not undefined behavior. The behavior is undefined when the value of the function call is used by the caller in this case. The code shown in example2 nowhere uses the value ofmultiply_by_2()
function call.
– H.S.
Mar 9 at 2:52
@H.S.: Huh. Learn something new every day. N1570, 5.9.1 Function definitions, item #12: "If the}
that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined."
– ShadowRanger
Mar 13 at 13:37
@ShadowRanger Of course and that what I wrote in my comment - The behavior is undefined when the value of the function call is used by the caller in this case. In this sentence by "in this case", I am referring the case where the function is suppose to return some value but the return statement is missing.
– H.S.
Mar 13 at 13:53
@H.S.: Yeah, I was thanking you for pointing that out and providing the associated reference. I was surprised, and looked it up for myself; figured I'd save others the effort. :-)
– ShadowRanger
Mar 13 at 14:38
3
3
you have an int returning function which does not return any integer. This is undefined behavior. No, this is not undefined behavior. The behavior is undefined when the value of the function call is used by the caller in this case. The code shown in example2 nowhere uses the value of
multiply_by_2()
function call.– H.S.
Mar 9 at 2:52
you have an int returning function which does not return any integer. This is undefined behavior. No, this is not undefined behavior. The behavior is undefined when the value of the function call is used by the caller in this case. The code shown in example2 nowhere uses the value of
multiply_by_2()
function call.– H.S.
Mar 9 at 2:52
@H.S.: Huh. Learn something new every day. N1570, 5.9.1 Function definitions, item #12: "If the
}
that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined."– ShadowRanger
Mar 13 at 13:37
@H.S.: Huh. Learn something new every day. N1570, 5.9.1 Function definitions, item #12: "If the
}
that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined."– ShadowRanger
Mar 13 at 13:37
@ShadowRanger Of course and that what I wrote in my comment - The behavior is undefined when the value of the function call is used by the caller in this case. In this sentence by "in this case", I am referring the case where the function is suppose to return some value but the return statement is missing.
– H.S.
Mar 13 at 13:53
@ShadowRanger Of course and that what I wrote in my comment - The behavior is undefined when the value of the function call is used by the caller in this case. In this sentence by "in this case", I am referring the case where the function is suppose to return some value but the return statement is missing.
– H.S.
Mar 13 at 13:53
@H.S.: Yeah, I was thanking you for pointing that out and providing the associated reference. I was surprised, and looked it up for myself; figured I'd save others the effort. :-)
– ShadowRanger
Mar 13 at 14:38
@H.S.: Yeah, I was thanking you for pointing that out and providing the associated reference. I was surprised, and looked it up for myself; figured I'd save others the effort. :-)
– ShadowRanger
Mar 13 at 14:38
add a comment |
The problem was that I should add a declaration of the functions in main.c, even though my compiler wouldn't warne me about it. With the declarations, all bugs are gone
1
I suspect turning up your warning level would get a warning output. Undeclared functions are kind of basic.
– ShadowRanger
Mar 9 at 2:31
2
Actually, you should have some common header file and include it everywhere. Copy & pasting the same declaration in several files is not scalable and should be avoided (unless perhaps your C source files are generated from something else; then the generator could duplicate declarations)
– Basile Starynkevitch
Mar 9 at 3:01
add a comment |
The problem was that I should add a declaration of the functions in main.c, even though my compiler wouldn't warne me about it. With the declarations, all bugs are gone
1
I suspect turning up your warning level would get a warning output. Undeclared functions are kind of basic.
– ShadowRanger
Mar 9 at 2:31
2
Actually, you should have some common header file and include it everywhere. Copy & pasting the same declaration in several files is not scalable and should be avoided (unless perhaps your C source files are generated from something else; then the generator could duplicate declarations)
– Basile Starynkevitch
Mar 9 at 3:01
add a comment |
The problem was that I should add a declaration of the functions in main.c, even though my compiler wouldn't warne me about it. With the declarations, all bugs are gone
The problem was that I should add a declaration of the functions in main.c, even though my compiler wouldn't warne me about it. With the declarations, all bugs are gone
answered Mar 9 at 2:29
Guerlando OCsGuerlando OCs
827
827
1
I suspect turning up your warning level would get a warning output. Undeclared functions are kind of basic.
– ShadowRanger
Mar 9 at 2:31
2
Actually, you should have some common header file and include it everywhere. Copy & pasting the same declaration in several files is not scalable and should be avoided (unless perhaps your C source files are generated from something else; then the generator could duplicate declarations)
– Basile Starynkevitch
Mar 9 at 3:01
add a comment |
1
I suspect turning up your warning level would get a warning output. Undeclared functions are kind of basic.
– ShadowRanger
Mar 9 at 2:31
2
Actually, you should have some common header file and include it everywhere. Copy & pasting the same declaration in several files is not scalable and should be avoided (unless perhaps your C source files are generated from something else; then the generator could duplicate declarations)
– Basile Starynkevitch
Mar 9 at 3:01
1
1
I suspect turning up your warning level would get a warning output. Undeclared functions are kind of basic.
– ShadowRanger
Mar 9 at 2:31
I suspect turning up your warning level would get a warning output. Undeclared functions are kind of basic.
– ShadowRanger
Mar 9 at 2:31
2
2
Actually, you should have some common header file and include it everywhere. Copy & pasting the same declaration in several files is not scalable and should be avoided (unless perhaps your C source files are generated from something else; then the generator could duplicate declarations)
– Basile Starynkevitch
Mar 9 at 3:01
Actually, you should have some common header file and include it everywhere. Copy & pasting the same declaration in several files is not scalable and should be avoided (unless perhaps your C source files are generated from something else; then the generator could duplicate declarations)
– Basile Starynkevitch
Mar 9 at 3:01
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073435%2fdeclaring-function-on-another-c-file-makes-float-multiplication-always-be-0%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You don't need
cmake
for such a simple example– Basile Starynkevitch
Mar 9 at 2:36
1
Clearly this doesn't compile, or at least shouldn't.
printf()
isn't declared ina.c
, andmultiply_by_2()
isn't declared inmain.c
... show the full code.– Havenard
Mar 9 at 3:07