|
#pragma wanring (disable: 6011)
If you know your code is working, you can dispense with the VS silliness.
Mircea
|
|
|
|
|
As the above poster said, I'm a well seasoned developer inheriting a code base that no one has looked at in 20 years. Since I'm not retired or dead yet...
point taken on warnings, but I have been burned too many times by other developers turning off warnings. I take the phrase "Here be dragons..." seriously.
Still I'm amazed that the MS compiler would distinguish between either version of the source.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
charlieg wrote: I take the phrase "Here be dragons..." seriously. And so you should. Seems the author of the code in question also took it seriously:
void CInfoBar::SetText(LPCTSTR lpszNew)
{
ASSERT(lpszNew && AfxIsValidString(lpszNew)); In this case assert seems the proper way to handle a failing precondition: the function cannot work with a NULL pointer. Fullstop!
In the new variant something has changed:
if (NULL != lpszNew)
{
ASSERT(lpszNew && AfxIsValidString(lpszNew)); The ASSERT after the if is clearly not needed (or it could be simplified to keep just the second condition). Also, more importantly the contract conditions of the function have changed: previously the function said "I cannot deal with NULL values for lpszNew". Now it says "if you pass me a NULL value I'm going to do something about it (possibly an else clause for the if statement or something)".
I'm not saying this is wrong but is something to consider carefully.
PS:
charlieg wrote: Still I'm amazed that the MS compiler would distinguish between either version of the source. It's the artificial intelligence
Mircea
|
|
|
|
|
I know my code is correct. But is my code completing all the demands of the question.
Q2: Let A[n] be an array of n distinct integers. If i < j and A[i] > A[j], then the pair (i, j)
is called an inversion of A. Write a C/C++ program that determines the number of
inversions in any permutation on n elements in O(n lg n) worst-case time.
(Hint: Modify merge sort)
Example: A = {4, 1, 3, 2} output is 4
#include<stdio.h>
int total_inversions(int arr[], int n, int count);
int main(){
int arr[] = {4, 1, 3, 2};
int n = sizeof(arr) / sizeof(arr[0]);
int count = 0;
count = total_inversions(arr, n , count);
printf("%d", count);
return 0;
}
int total_inversions(int arr[], int n, int count){
for(int i = 0; i < n-1; i++){
for(int j = i+1; j < n; j++){
if (arr[i] > arr[j]){
count++;
}
}
}
return count;
}
|
|
|
|
|
You're going to have to ask your teacher that question.
|
|
|
|
|
Aryan Gupta 2024 wrote: I know my code is correct. But is my code completing all the demands of the question.
Technically, if it's not "completing all the demands of the question", then it's not "correct".
For example, this random number generator code[^] is "correct" in the sense that it compiles and works. But it's not "correct" in the sense of fulfilling the requirements of an RNG function.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
'Your' random generator code is simply fantastic!
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
I have a cloned "wrapper'
header file containing other headers.
The compiler fails to find one of them.
But file manager has no problem opening it.
I checked the contents of the file and it looks similar to
other headers.
\
<pre>#ifndef DBUS_H
#define DBUS_H
#define DBUS_INSIDE_DBUS_H 1
#include <dbus/dbus-arch-deps.h>
#include <dbus/dbus-address.h>
#include <dbus/dbus-bus.h>
#include <dbus/dbus-connection.h>
#include <dbus/dbus-errors.h>
#include <dbus/dbus-macros.h>
#include <dbus/dbus-message.h>
#include <dbus/dbus-misc.h>
#include <dbus/dbus-pending-call.h>
#include <dbus/dbus-protocol.h>
#include <dbus/dbus-server.h>
#include <dbus/dbus-shared.h>
#include <dbus/dbus-signature.h>
compiler l,fails to "find" this file ONLY
#include <dbus/dbus-syntax.h>
#include <dbus/dbus-threads.h>
#include <dbus/dbus-types.h>
#undef DBUS_INSIDE_DBUS_H
here is FULL compiler error
<pre>/usr/include/dbus-1.0/dbus/dbus.h:42: error: 'dbus/dbus-syntax.h' file not found
In file included from BT_CONNECT.cpp:14:
In file included from ../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simplebluez/include/simplebluez/Adapter.h:2:
In file included from ./../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simpledbus/include/simpledbus/advanced/Proxy.h:3:
In file included from ../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simpledbus/include/simpledbus/advanced/Interface.h:3:
In file included from ../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simpledbus/include/simpledbus/base/Connection.h:18:
/usr/include/dbus-1.0/dbus/dbus.h:42:10: fatal error: 'dbus/dbus-syntax.h' file not found
#include <dbus/dbus-syntax.h>
^~~~~~~~~~~~~~~~~~~~
I am asking for suggestion(s) how to convince the compiler that the file does exists.
Or what could be wrong with the header source, and way to temporary bypass it so ,I can compile the code.
PS
If it helps I could post the header source here...
|
|
|
|
|
Have you updated the "additional include directories" in the project settings ?
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
That is not (very) logical.
There is series of "includes" from same resource and they are "found".
I can open the file, so what is stopping the compiler to "find" it?
|
|
|
|
|
Where exactly did you find that file?
|
|
|
|
|
Salvatore Terress wrote: #include <dbus/dbus-signature.h>
compiler l,fails to "find" this file ONLY
#include <dbus/dbus-syntax.h>
You can verify this by deleting the first file - then you should get the error for that first file. If you delete it and the error does NOT occur then you are looking at the wrong directory.
But if those two files are in the same directory then the problem is a permission problem.
Probably with the file.
But there are other possible variations such as that the file is actually a link and the link location (hierarchy) has a permission problem.
|
|
|
|
|
!!! pkg-config is your friend !!!
Here's a very simple program that #includes <dbus/dbus.h>
#include <iostream>
#include <dbus/dbus.h>
int main()
{
std::cout << "Hello World\n";
}
Clearly, this does nothing but print "Hello World", but does ask the compiler to #include <dbus/dbus.h>
If we try to compile this naively, the compiler complains that it can't find the requested headers
k5054@localhost:~/tmp $ g++ hello.cpp
hello.cpp:2:10: fatal error: dbus/dbus.h: No such file or directory
2 | #include <dbus/dbus.h>
| ^~~~~~~~~~~~~
compilation terminated.
pkg-config --cflags dbus-1 returns the magic needed to find the headers:
k5054@localhost:~/tmp $ pkg-config --cflags dbus-1
-I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include I've been over this before in answer to your question in QA I think, so I'm not going to repeat it here.
We can use some shell "magic" to tell the compiler to use pkg-config to find the headers:
k5054@localhost:~/tmp$ g++ $(pkg-config --cflags dbus-1) hello.cpp
k5054@localhost:~/tmp$ ./a.out
Hello World
k5054@localhost:~/tmp$ This clearly finds the requested headers and compiles the program successfully. I'd recommend that you try this from the command line exactly as shown here. If you get a successful compile, you need to dig into your IDE and find out how to configure it correctly. If this doesn't work for you, then you've probably ed up your linux installation, and my best recommendation would be to back anything you want to keep, purge your drives, then reinstall. Before recovering your backed up files, make sure that the above simple program will compile. If not, you need to figure out why.
In over 30 years of working with Unix like systems, the only time I've copied headers under /usr/include, or /usr/local/include to a local project was when I've been trying to do something weird, like trying to compile a new package on an obsolete OS [think trying to get a new version of GCC to compile on RedHat 9 (circa 2003)] or vice versa, e.g getting gcc-2.95 to compile on RedHat Fedora 37. If you find yourself copying includes from the system include directories then IMHO you're making a mistake, and clearly don't understand the build process. That would be true if you find yourself doing this on a Windows system as well.
Don't forget that in order to link to the dbus libraries, you'll need to add pkg-config --libs dbus-1 somewhere so that the link phase knows where to find the needed libraries.
Knowing that the -I flag tells the compiler where to look for include files is simple, basic unix developer course 101 stuff. You shouldn't have any issues understanding that if you've spent more than a couple of weeks doing any Linux or Unix development. The only thing I can think is that you've become over dependent on your IDE and you're not understanding the basic Linux development ecosystem. It might be worth while to break out one or two of the functional parts of your project from the UI/IDE and get them to compile using nothing more sophisticated than a Makefile. If you can get that done, and your IDE keeps breaking the build, you'll probably be better equipped to dig into the IDE settings and figure out what needs to be altered to get it to work.
Good Luck
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
|
|
|
|
|
Thanks for such exhaustive reply. Appreciate that very much. It does not answer why specific header out of many is "missing". I did change the reference to "/dbus.." - instead of being "at the end of thee #include chain" be "direct" , but with same result.
I suspect the cloning process is the issue.
I am going to build (clone) a separate project , maybe use a different example, from the github.
|
|
|
|
|
I still think you're doing something wrong. What github repository are you using? Maybe I'll give it a try and see if I get the same results ... In which case it means that the repository may have issues and the maintainers should be alerted.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
|
|
|
|
|
Myself I don't know what github would have to do with it.
When it compiles either the file is there or not. Or it is accessible or not.
How does Git impact unless git is causing one of those specific problems?
|
|
|
|
|
My suspicion is that at least one of the following is true:
A) the OP is not following the compilation instructions from the git repo
B) the OP has not added the prerequisites for the repo to compile
C) the repo does not list what resources are needed (e.g dev libraries, cmake, etc). Or that information is buried somewhere in the repo source files, and the OP has not stumbled upon it, yet.
The OP also has some odd notion that he can "fix" things by copying header files from somewhere in /usr/include to the local directory. My experience suggests that 99.99% of the time, this will not work, and is about the worst solution I could think of to get things to compile.
"A little song, a little dance, a little seltzer down your pants"
Chuckles the clown
|
|
|
|
|
I'm currently working on a lattice Boltzmann code (D3Q27) employing MPI for parallelization. I've implemented MPI 3D topology for communication, and my code snippet handles communication as follows, I also have the same structure for the communication between front-back and up-down.
void Simulation::Communicate(int iter) {
int tag_xp = 0;
int tag_xm = 1;
int tag_yp = 2;
int tag_ym = 3;
int tag_zp = 4;
int tag_zm = 5;
MPI_Status status;
if (SubDomain_.my_right_ != MPI_PROC_NULL) {
std::vector<double> send_data;
for (int k = 0; k < SubDomain_.my_Nz_; k++) {
for (int j = 0; j < SubDomain_.my_Ny_; j++) {
if (SubDomain_.lattice_[SubDomain_.my_Nx_ - 2][j][k] == nullptr) {
for (int dir = 0; dir < _nLatNodes; dir++) {
send_data.push_back(0.0);
}
}
else {
for (int dir = 0; dir < _nLatNodes; dir++) {
send_data.push_back(SubDomain_.lattice_[SubDomain_.my_Nx_ - 2][j][k]->m_distributions[dir]);
}
}
}
}
std::vector<double> recv_data(send_data.size());
MPI_Sendrecv(send_data.data(), send_data.size(), MPI_DOUBLE, SubDomain_.my_right_, tag_xp,
recv_data.data(), recv_data.size(), MPI_DOUBLE, SubDomain_.my_right_, tag_xm,
MPI_COMM_WORLD, &status);
int index = 0;
for (int k = 0; k < SubDomain_.my_Nz_; k++) {
for (int j = 0; j < SubDomain_.my_Ny_; j++) {
for (int dir = 0; dir < _nLatNodes; dir++) {
SubDomain_.lattice_[SubDomain_.my_Nx_ - 1][j][k]->m_distributions[dir] = recv_data[index];
index++;
}
}
}
}
if (SubDomain_.my_left_ != MPI_PROC_NULL) {
std::vector<double> send_data;
for (int k = 0; k < SubDomain_.my_Nz_; k++) {
for (int j = 0; j < SubDomain_.my_Ny_; j++) {
if (SubDomain_.lattice_[1][j][k] == nullptr) {
for (int dir = 0; dir < _nLatNodes; dir++) {
send_data.push_back(0.0);
}
}
else {
for (int dir = 0; dir < _nLatNodes; dir++) {
send_data.push_back(SubDomain_.lattice_[1][j][k]->m_distributions[dir]);
}
}
}
}
std::vector<double> recv_data(send_data.size());
MPI_Sendrecv(send_data.data(), send_data.size(), MPI_DOUBLE, SubDomain_.my_left_, tag_xm,
recv_data.data(), recv_data.size(), MPI_DOUBLE, SubDomain_.my_left_, tag_xp,
MPI_COMM_WORLD, &status);
int index = 0;
for (int k = 0; k < SubDomain_.my_Nz_; k++) {
for (int j = 0; j < SubDomain_.my_Ny_; j++) {
for (int dir = 0; dir < _nLatNodes; dir++) {
SubDomain_.lattice_[0][j][k]->m_distributions[dir] = recv_data[index];
index++;
}
}
}
}
}
While I can verify that communication occurs correctly by printing sent and received data, upon visualization, it appears that the data might not be transferring to neighboring processors as expected, despite not being zeroed out (as previously confirmed through printing). After each iteration, I visualize the velocity components obtained via the Lattice Boltzmann Method (LBM). My observation reveals that the fluid dynamics are solely resolved within the processor featuring the inlet boundary condition, while all other processors exhibit a velocity of zero. This suggests that data transfer to neighboring processors might not be occurring as expected.
I have a couple of concerns:
Could data corruption arise from blocking communication? Is diagonal communication necessary? My understanding is that if communication in the normal directions (x, y, and z) is established, diagonal communication implicitly occurs. Additionally, I'm uncertain about the order of communication. Do all communications happen simultaneously, or is it sequential (e.g., right and left, then front and back, then up and down)? If they're not simultaneous, would diagonal communication be required?
I also have a confusion in receiver processor id. for example
MPI_Sendrecv(send_data.data(), send_data.size(), MPI_DOUBLE, SubDomain_.my_right_, tag_xp, recv_data.data(), recv_data.size(), MPI_DOUBLE, SubDomain_.my_right_, tag_xm, MPI_COMM_WORLD, &status); should it be SubDomain_.myrank_, instead of SubDomain_.my_right_ in receive part?
I'd appreciate any insights to clarify these points of confusion. Thank you!
|
|
|
|
|
Use code tags when you post code.
The context of your questions is not clear.
There is theory and there is practice (implementation). To which do your questions refer?
Are you asking if your code is right? And only that?
Are you asking if your theory is right? And only that?
If the second then the code doesn't help.
If the first then you should provide some specifics about which part of the code you think has a problem.
If you are mixing the two then I would suggest that you rethink what it is that you actually need to ask.
I suspect also that at least for the theory you need to run on hardware that tests this. Not clear to me how your code insures that the hardware is even being used. That however might both be because you didn't use code tags and because I didn't look that closely at the code.
|
|
|
|
|
I have "include" (cloned) a full project from "github".
It is missing ONE header file, hence ,it won't compile.
I have found another resource which contains the missing file.
This resource appears to be a "stand alone" header
and it does not give much explanation how to use it.
I am asking for suggestion
how to "merge" these resources,
basically how to
change the working clone "dbus/files"
to
"stand alone " "dbus/files"
Simple
include both does not work
Here is my current setup
UNDER construction
<pre>
this contains the missing header BUT NO OTHER CODE !
INCLUDEPATH += "/home/nov25-1/Downloads/nobus-master/include/dbus-1.0/dbus"
# temp removed contains usable code, but missing ONE header file
INCLUDEPATH += "../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simplebluez/include/simplebluez/"
#INCLUDEPATH += "../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simplebluez/include/"
#INCLUDEPATH += "../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simplebluez/simpledbus/advanced/"
#INCLUDEPATH += "../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simpledbus/include/"
///usr/include/core/dbus/dbus.h
#INCLUDEPATH += "/usr/include/"
#INCLUDEPATH += "/usr/include/dbus-1.0/"
# links to first dbus.h "missing" file
#INCLUDEPATH += "/usr/lib64/dbus-1.0/include/"
#INCLUDEPATH += "/home/nov25-1/Downloads/nobus-master/include/dbus-1.0/dbus"
# INCLUDEPATH += "/mnt/A_BT_DEC10/BT__PROGRAMS/A_JAN11 _FEB26/A_BT_LIBRARY/CCC_SOURCE/BT_no_bus/nobus-master/include/dbus-1.0"
#//dding -I/usr/lib64/dbus-1.0/include/ in c
#include <dbus/dbus-arch-deps.h>
INCLUDEPATH += "../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simpledbus/include/"
INCLUDE_DIRECTORIES("../../A_BT_LIBRARY/SimpleBluetooth/SimpleBLE-main/simplebluez/include/simplebluez")
#INCLUDEPATH = c:/msdev/include d:/stl/include
PS.
If it is unclear what I am asking for
please ask for clarification.
|
|
|
|
|
You can add any header files to your project repository, or in another location using the INCLUDEPATH variable as you have shown. But I am not sure what you mean by "a "stand alone" header", so yes, your question is not clear. Maybe if you showed the relevant code plus any error messages, it will become clearer.
|
|
|
|
|
Salvatore Terress wrote: I have "include" (cloned) a full project from "github"
Presumably you mean a single repo.
Salvatore Terress wrote: how to "merge" these resources,
Repo A has the code.
Repo B has the include file.
Copy the file from B and put it into A.
You do nothing at all with B after that.
Modify whatever you need to in A so the include file, in A, is used correctly. Compile and test A.
|
|
|
|
|
That is what I thought would work...
I may have to change A to be read / write...
I'll let you know the outcome...
Thanks
|
|
|
|
|
|
which github ?
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|