Alex
Yeah but int x, y, z would do the same and everyone cam read it
that`s what I meant. Pavel wrote each var should be declared on separate line
Najam
Yeah right
olli
why not int *a, *b ? you know its pointer and would check for NULL for example. also you know this is first rank
Both are fine to me. The advantages I see in having the typedef - no useless discussions on where to put the * - can't "forget" the * - can't have multiple variables of different types in the same line
神話♠
#notename
Najam
Anyone have webdevelopment group ?
Alex
Both are fine to me. The advantages I see in having the typedef - no useless discussions on where to put the * - can't "forget" the * - can't have multiple variables of different types in the same line
1.weak argument..2. if you forget * most likely you would get compilation error. 3. if its the problem(however I don`t understand why) just don`t do it.
Pavel
that`s what I meant. Pavel wrote each var should be declared on separate line
Yes, in a pod struct declaration what you wrote can make sense (since you're not going to initialize them by default). But it you write some logic you either use a struct instead of that (since they are bound together anyway), or initialize them int x = value1, y = value1, z = value3; Which is not readable anymore. Or better yet you initialize a variable right before using it. int x = smt. int z = smt + ... * x; int y = smt ... x ... z; There may be a case when you need to pass several vars as out params to some function, but in C++ you would better return several values as a tuple to increase readability. For C I guess your version should be fine.
olli
1.weak argument..2. if you forget * most likely you would get compilation error. 3. if its the problem(however I don`t understand why) just don`t do it.
1. yes and no. Having consistency is not a wear argument (imo) and by not having a typedef you either need to manually validate every change for consistency or you need to setup some infrastructure that automates that part. Using a typedef provides this consistency for "free" 2. I still think you should prevent mistakes and errors as soon as possible.
Alex
why not int *a, *b ? you know its pointer and would check for NULL for example. also you know this is first rank
Ishank
Is turbo c+ a good app for coding C language?
Alex
if I read int *a I know how to work with. If I face with pint a, I should find in source what is pint. And I could deal with it like non ptr type(cause I don`t what is pint).
Alex
Is turbo c+ a good app for coding C language?
I think no, cause its out of the C standard
Ishank
I think no, cause its out of the C standard
Then suggest me a better application :)
olli
if I read int *a I know how to work with. If I face with pint a, I should find in source what is pint. And I could deal with it like non ptr type(cause I don`t what is pint).
this is true for every type, so you could only use primitive types in C. Decent editors or IDEs will be able to help you. Additionally this is a one-off cost, whereas you would need to pay attention for the placement every time you use it.
Pavel
VS or QtCreator
olli
Then suggest me a better application :)
Visual Studio or Visual Studio Code + GCC
Alex
this is true for every type, so you could only use primitive types in C. Decent editors or IDEs will be able to help you. Additionally this is a one-off cost, whereas you would need to pay attention for the placement every time you use it.
1. there is special treatment for ptr type. for example we usually validate it for NULL if its function argument. 2. there are no other options for struct, or union. in this cause you can simply use int *a. If you have to pass pint to function would you use pint or *pint? you should check what is pint first. If you have int* and don`t need to change address you just you *int
Alex
it is still a "ptr type", so you can still check it for NULL #include <stdlib.h> typedef int* pint; void Foo(pint a) { if (a == NULL) { return; } // ... }
lets work with huge code source. We have hundreds of pint, pfloat, pdouble, pcustomtype and so on. some of them are pointers, some of them not like parent . do we have arent type? also pint could be defined in third party lib, so you have multiple definition. So now you should find out what is pint in source jungles. for hello world project almost any decision is ok
Alex
I do work with a huge code basis (> 10 million of lines) and it works great
that`s good. however I specified what are drawbacks for big source base
Alex
Actually code readability is usually the most important today. More code - less readability. Decrease it, to avoid potential discussions int *p vs int* p - doubtful idea
Igor🇺🇦
1. there is special treatment for ptr type. for example we usually validate it for NULL if its function argument. 2. there are no other options for struct, or union. in this cause you can simply use int *a. If you have to pass pint to function would you use pint or *pint? you should check what is pint first. If you have int* and don`t need to change address you just you *int
On my job we too have typedef to pointer type to make it easier to use. It's more readable than using *. Proper IDE shows what this type actually is. And you don't even need to know that most of the time anyway. Method gets pint - I'm sending pint.
Igor🇺🇦
what about creating your own method?
What about it? IDE shows me definition if I really need to know. If type is common I know already what type it is. How should that affect my decisions anyway?
Alex
What about it? IDE shows me definition if I really need to know. If type is common I know already what type it is. How should that affect my decisions anyway?
you need IDE with indexing, you should relay on it, you should check what is pint. what if mulpiple definitions of pint? I would simply use int*, less entities - easier to maintain code
Igor🇺🇦
you need IDE with indexing, you should relay on it, you should check what is pint. what if mulpiple definitions of pint? I would simply use int*, less entities - easier to maintain code
Yes, you need IDE to properly work with large databases. I prefer that mundane tasks are made automatically, that's what computers are for after all. Less stuff I need think about the better.
Igor🇺🇦
you need IDE with indexing, you should relay on it, you should check what is pint. what if mulpiple definitions of pint? I would simply use int*, less entities - easier to maintain code
Do think the same about CI, clang-format, linters, sanitisers etc.? "Who needs tools when you can do this manually?"
Alex
Do think the same about CI, clang-format, linters, sanitisers etc.? "Who needs tools when you can do this manually?"
no. these tools help to maintain code. the only drawback - you should devote more time to write in the right way.
RC
#include <stdlib.h> int main() { int n,count=0; scanf("%d",n); while(n>0) { count=n/10; count++; } printf("count %d",count); }
Anonymous
Hey guys, working on a long code so I am using multiple files. How do I include those files as headers without the use of file directory in let's say main.cpp
Anonymous
I want the compiler to see files as part of project's directory
Pavel
The loop does not work
Define "does not work", I see that you check for n > 0 and don't change n. So if n less or equal zero then no iterations will happen, otherwise the loop will go to the infinity
RC
What's the solution?
Igor🇺🇦
Hey guys, working on a long code so I am using multiple files. How do I include those files as headers without the use of file directory in let's say main.cpp
Every compiler has switch to add search path. For example https://www.rapidtables.com/code/linux/gcc/gcc-i.html
Pavel
What's the solution?
Solution is to fix your code so it does what you want it to do. I don't know what is expected behavior in this case.
Pavel
What's the solution?
If you make a loop, your exit condition result should change during its iterations, otherwise it will never end
Pavel
Sam
#include <stdlib.h> #include<stdio.h> int main() { int n,count=0,rem; scanf("%d",&n); while(n>0) { rem=n%10; n=n/10; count++; } printf("count %d",count); }
Pavel
It does not change
What does not change? Why do you think people can read your mind?
Anonymous
How do I fix a multiple definition of function error message?
Anonymous
I only used one definition; calling functions defined in non main cpp file and some how getting that error message
Anonymous
leave one definition, use namespace
Multiple files here, can I send them to use privately?
Igor🇺🇦
Yes
That's your problem. You should have only declaration in header, not implementation
Anonymous
https://pastebin.pl/view/b8408fc8
Anonymous
https://pastebin.pl/view/2642c9d3
Igor🇺🇦
https://pastebin.pl/view/2642c9d3
You're doing it wrong. You're not supposed to include cpp. You should include headers to cpp,
Anonymous
https://pastebin.pl/view/44a94b00
Igor🇺🇦
Please how do you mean?
https://docs.microsoft.com/en-us/cpp/cpp/header-files-cpp?view=msvc-160
Anonymous
Ok, reading them
Anonymous
Ok, reading them
I just realized that somehow I messed up my code unintentionally and unknowingly. Portions of the codes are displaced in the pattern.cpp
Maide
Hello everybody. I have 2 questions for you. Any idea for this questions please say to me. Thank you.
Maide
1) We have a legacy C library that is indispensable in a project. The code content of this library is not to be modified, but the library offers the ability to register callbacks that are preferably coded in C++ by the developer utilizing the library. How can such a callback mechanism be possible to construct, and what is an important detail concerning the C library and the signatures of the registered callback functions? Explain. 2) Similar to the C library in the previous question, a C++ library allows callback functions to be registered for utilization as well. Would you expect the C++ library to make use of the same callback mechanism as suggested in the previous question, or are there better alternatives that the C++ library possibly can offer? Explain.
Pavel
Or you mean that you have no choice but to use it?