I want add value to a atomic<__uint128_t> but i have this error
erreur : no match for ‘operator+=’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::atomic<__int128 unsigned> > >::value_type {aka std::atomic<__int128 unsigned>}’ and ‘const value_type {aka const std::atomic<__int128 unsigned>}’)
niveau[ranka(pre)]+=etage_fils[i];
with
"typedef __uint128_t longuint;"
my code :
vector<atomic<longuint>> (vector<atomic<longuint>> const & etage_fils, int eta){
vector<atomic<longuint>> niveau(mahonian(n,eta-2));
int limite = mahonian(n, eta-1);
cilk_for (int i = 0; i < limite; ++i)
{
vector<Permut> parents = prec(unrank(eta-1, i));
for (Permut const & pre : parents)
{
niveau[ranka(pre)]+=etage_fils[i];
}
}
return niveau;
}
I tried
niveau[ranka(pre)].fetch_add(etage_fils[i];
but don't works
Any help will be appreciated. thanks :)
Related
`
size_t pos = 0;
const u32 MAX_BACKTRACE_DEPTH = 20;
for (u32 cnt = MAX_BACKTRACE_DEPTH; cnt != 0; --cnt) {
if (err || curr_dentry == NULL) {
break;
}
int name_len = BPF_CORE_READ(curr_dentry, d_name.len);
const u8 *name = BPF_CORE_READ(curr_dentry, d_name.name);
if (name_len <= 1) {
break;
}
if (name_len + pos > 512) {
break;
}
name_len = bpf_probe_read_kernel_str(filename + pos, name_len, name);
if (name_len <= 1) {
break;
}
pos += name_len;
filename[pos - 1] = '/';
struct dentry *temp_dentry = BPF_CORE_READ(curr_dentry, d_parent);
if (temp_dentry == curr_dentry || temp_dentry == NULL) {
break;
}
curr_dentry = temp_dentry;
}
`
ebpf validator prompts "R2 unbounded memory access, use 'var &= const' or 'if (var < const)'" when the second argument to function bpf_probe_read_kernel_str is a variable.
I tried to add const to name_len and I couldn't.
You need to have a strict bound on that name_len variable. It is currently only bounded by 512 - pos which is not a constant.
void sensorConfig(void)
{
float buffer[SIZE];
char index = 0;
I2C1_Initialize();
I2C1_Open();
I2C1_MasterWrite(0xC7);
while(1)
{
for(index=0;index<SIZE;index++)
{
buffer[ index ] = I2C1_MasterRead(ACCEL_XOUT_H + index);
}
}
I2C1_Close();
}
void I2C1_Initialize()
{
SSP1STAT = 0x80;
SSP1CON1 = 0x08;
SSP1CON2 = 0x00;
SSP1ADD = 0x09;
SSP1CON1bits.SSPEN = 0;
}
error message:
main.c:118:: error: (1098) conflicting declarations for variable "_I2C1_Initialize" (mcc_generated_files/i2c1_master.c:167)
I am trying to establish a I2C connection between MPU6050 accelerometer and pic18f45k22
I would like to insert some character after each number of my string
I found how to insert before each character, but what I want is :
string str = "12 + 5"
insert ^ after each number
Output = "12^ + 5^"
Thank you for your help
Something like this should work:
int main()
{
char string[128] = "12 + 5";
char output[128] = {};
char side_string[128] = {};
int pos_string = 0;
for (pos_string = 0; pos < length(string); pos_string ++) {
if (string[pos_string] < '0' && string[pos_string] > '9') {
if (strlen(side_string) > 0) {
strcat(output, side_string);
strcat(output, "^");
side_string[0] = 0;
}
output[strlen(output)] = string[pos_string];
} else {
side_string[strlen(side_string)] = string[pos_string];
}
}
if (strlen(side_string) > 0) {
strcat(output, side_string);
strcat(output, "^");
side_string[0] = 0;
}
NOTE:
The code is inefficient, but it is written for simplicity rather than briefness
The code is INSECURE there is no length checking and no validation of BO
I have a merge sort and it will work when I do
mergeSort<int>(val_array1,numValues);
but once I change it to float
mergeSort<float>(val_array2,numValues);
I get this error:
1>c:\users\cbadau\documents\visual studio 2010\projects\lab\lab\lab12.cpp(71): error C2782: 'void recMergeSort(ItemType [],ItemType,ItemType)' : template parameter 'ItemType' is ambiguous
1> c:\users\cbadau\documents\visual studio 2010\projects\lab\lab\lab12.cpp(58) : see declaration of 'recMergeSort'
1> could be 'int'
1> or 'float'
1> c:\users\cbadau\documents\visual studio 2010\projects\lab\lab\lab12.cpp(96) : see reference to function template instantiation 'void mergeSort<float>(ItemType [],int)' being compiled
1> with
1> [
1> ItemType=float
1> ]
1>
Source Code:
#include<iostream>
using namespace std;
template<class ItemType>
void merge(ItemType list[], ItemType first, ItemType last, ItemType mid)
{
ItemType arraySize = last - first + 1;
ItemType* tempList = new ItemType[arraySize];
ItemType beginPart1 = first;
ItemType endPart1 = mid;
ItemType beginPart2 = mid + 1;
ItemType endPart2 = last;
int index = 0;
while (beginPart1 <= endPart1 && beginPart2 <= endPart2) {
if (list[beginPart1] < list[beginPart2]) {
tempList[index] = list[beginPart1];
beginPart1++;
}
else {
tempList[index] = list[beginPart2];
beginPart2++;
}
index++;
}
while (beginPart1 <= endPart1) {
tempList[index] = list[beginPart1];
index++;
beginPart1++;
}
while (beginPart2 <= endPart2) {
tempList[index] = list[beginPart2];
index++;
beginPart2++;
}
for (int i = first; i <= last; i++) {
list[i] = tempList[i - first];
}
delete[] tempList;
}
template<class ItemType>
void recMergeSort(ItemType list[], ItemType first, ItemType last)
{
if (first < last) {
ItemType mid = (first + last) / 2;
recMergeSort(list, first, mid);
recMergeSort(list, mid + 1, last);
merge(list, first, last, mid);
}
}
template<class ItemType>
void mergeSort(ItemType list[], int length)
{
recMergeSort(list, 0, length - 1);
}
int main()
{
int val_array1[] = {43, 7, 10, 23, 38, 4, 19, 51, 66, 14};
float val_array2[] = {43.2, 7.1, 10.5, 3.9, 18.7, 4.2, 19.3, 5.7, 66.8, 14.4};
int numValues = 10;
cout<<"val_array1 unsorted: "<<endl;
for(int i = 0; i <numValues; i++)
{
cout<<val_array1[i]<<endl;
}
cout<<"val_array2 unsorted: "<<endl;
for(int x=0; x <numValues; x++)
{
cout<<val_array2[x]<<endl;
}
mergeSort<int>(val_array1,numValues);
mergeSort<float>(val_array2,numValues);
cout<<"val_array1 sorted: "<<endl;
for(int y = 0; y <numValues; y++)
{
cout<<val_array1[y]<<endl;
}
cout<<"val_array2 sorted: "<<endl;
for(int t=0; t <numValues; t++)
{
cout<<val_array2[t]<<endl;
}
system("pause");
return 0;
}
Any ideas on what the problem is?
You have the same type for the values as for the indices in your template. Change ItemType to int for first, last, mid, etc.
I wrote a solution that involved OpenProcess, EnumProcessModules, GetModuleInformation and GetModuleBaseName, but apparently EnumProcessModules and GetModuleBaseName do not exist in Windows CE! What alternative is there?
I found a way to do this with CreateToolhelp32Snapshot, Module32First, Module32Next, Process32First and Process32Next. First you have to get a list of modules, then search through the list of modules to find the desired address.
#include <Tlhelp32.h>
struct MyModuleInfo
{
BYTE* Base;
HMODULE Handle;
DWORD Size;
enum { MaxNameLen = 36 };
TCHAR Name[MaxNameLen];
};
bool GetModuleList(vector<MyModuleInfo>& moduleList)
{
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS | TH32CS_SNAPMODULE | TH32CS_GETALLMODS, 0);
if (hSnapshot == INVALID_HANDLE_VALUE)
return false;
MODULEENTRY32 moduleInfo;
moduleInfo.dwSize = sizeof(moduleInfo);
if (Module32First(hSnapshot, &moduleInfo)) do {
MyModuleInfo myInfo;
myInfo.Handle = moduleInfo.hModule;
myInfo.Base = moduleInfo.modBaseAddr;
myInfo.Size = moduleInfo.modBaseSize;
memcpy(myInfo.Name, moduleInfo.szModule, min(sizeof(myInfo.Name), sizeof(moduleInfo.szModule)));
myInfo.Name[myInfo.MaxNameLen-1] = '\0';
moduleList.push_back(myInfo);
} while (Module32Next(hSnapshot, &moduleInfo));
// The module list obtained above only contains DLLs! To get the EXE files
// also, we must call Process32First and Process32Next in a loop.
PROCESSENTRY32 processInfo;
processInfo.dwSize = sizeof(processInfo);
if (Process32First(hSnapshot, &processInfo)) do {
MyModuleInfo myInfo;
myInfo.Handle = NULL; // No handle given
myInfo.Base = (BYTE*)processInfo.th32MemoryBase;
myInfo.Size = 0x800000; // No size provided! Allow max 8 MB
memcpy(myInfo.Name, processInfo.szExeFile, min(sizeof(myInfo.Name), sizeof(processInfo.szExeFile)));
myInfo.Name[myInfo.MaxNameLen-1] = '\0';
moduleList.push_back(myInfo);
} while(Process32Next(hSnapshot, &processInfo));
// Debug output
for (int i = 0; i < (int)moduleList.size(); i++) {
MyModuleInfo& m = moduleList[i];
TRACE(_T("%-30s: 0x%08x - 0x%08x\n"), m.Name, (DWORD)m.Base, (DWORD)m.Base + m.Size);
}
CloseToolhelp32Snapshot(hSnapshot);
return true;
}
const MyModuleInfo* GetModuleForAddress(vector<MyModuleInfo>& moduleList, void* address)
{
for (int m = 0; m < (int)moduleList.size(); m++) {
const MyModuleInfo& mInfo = moduleList[m];
if (address >= mInfo.Base && address < mInfo.Base + mInfo.Size)
return &mInfo;
}
return NULL;
}