Alignant
int var = 5;
void somefunc()
{
// some code
}
int main()
{
var++;
return 0;
}
Are you doing it like this?
_̸̡͝͝This
_̸̡͝͝This
More like this :
_̸̡͝͝This
int black = 5;
void foo() {
black = 0;
}
int main(int argc, char const *argv[]) {
foo();
return 0;
}
olli
this works as well, globals such as your variable black can be accessed form everywhere
Alignant
I think you made a typo somewhere, this is valid
Alignant
From everywhere in this file :D
_̸̡͝͝This
Yes, I'm checking with an online compiler and it works
_̸̡͝͝This
Must be a problem with my compiler then...
olli
that's one of the problems with globals
Alignant
_̸̡͝͝This
Okay... I found the issue
_̸̡͝͝This
The variables must be defined BEFORE you define the function
_̸̡͝͝This
I though the compiler started compiling the global variables and then the functions lol
Onur
Do I need to include any header to use size_t?
Sercan
Alignant
True :D
No you don't by the way
Onur
but it just compiles when I define a variable with size_t
_̸̡͝͝This
Thank you guys for helping me so much !
Roxifλsz 🇱🇹
/warn bitcoin ad
Anonymous
int i, sum;
int * ptr = malloc(5 * sizeof(int));
for (i = 0; i< 5; i++)
*(ptr + i) = i;
How come the value always zero ?
Jussi
Which value?
Anonymous
Which value?
ptr[0] = 0;
ptr[1] = 0;
ptr[2] = 0;
ptr[3] = 0;
ptr[4] = 0;
Jussi
How do you print them out?
Jussi
:)
Dominic
So what's the difference between C ++ and python
Sercan
Sercan
_̸̡͝͝This
Hi, uhm, is there any reason why doing an assignment with a pointer inside
_̸̡͝͝This
Okay, nevermind 😅
Dominic
Kk
Jussi
Why is c++ hated?
Jussi
So what's the difference between C ++ and python
The main difference is that for python you run the source code itself. There is a python interpreter that does the actual job, your code just instructs that interpreter. In C(++), you need to COMPILE your code so it becomes machine code that will be directly executed. There is no need for interpreter for C languages, but you need to compile your code into an executable before you can run it
Anonymous
Hi everyone
Anonymous
I had learned basic programming in my first year of college and then things went wrong in life for two years. I have dropped out but still want to learn programming.
Anonymous
Returning to learn again after almost three years. Forgive me if I ask very simple and basic questions at times.
Sercan
Anonymous
Thank you. I look forward to learning from you all.
Onur
Is it possible to make a variable inside a class only to visible from its namespace?
Onur
Like internal keyword in c#
Zorrito
I know this may be a noob question, but I'm working with a library (QPULib) which functions by compiling and running kernels, and I'm having problems with making it working correctly. So, a kernel accesses shared arrays through pointers, but it doesn't seem to like when I use the same array as an input and an output. Is the language just set up such that it's impossible to do that? Do I really need to create a secondary array just to appease the C++ gods, or is there a way around it?
Anonymous
Anonymous
Are you trying to do something like this?
Anonymous
myfunction(char output[], char input[]){
copy(output, input)
}
...
char output[] = "Hola, como estas";
myfunction(output, output)
Anonymous
Anonymous
Anonymous
Zorrito
https://github.com/mn416/QPULib
Anonymous
#include <stdio.h>
void
copy(float p[], float q[], int n)
{
int i;
for(i = 0; i < n; i++){
p[i] = p[i]+q[i];
}
}
int
main()
{
int i, n = 7; // n is len of a
float a[] = {0.1, .2, .3, .4, .5, .6, .7};
copy(a, a, n);
for (i = 0; i < n; i++)
printf("%f\n", a[i]);
return 0;
}
Anonymous
Example in c
Zorrito
#include <stdio.h>
void
copy(float p[], float q[], int n)
{
int i;
for(i = 0; i < n; i++){
p[i] = p[i]+q[i];
}
}
int
main()
{
int i, n = 7; // n is len of a
float a[] = {0.1, .2, .3, .4, .5, .6, .7};
copy(a, a, n);
for (i = 0; i < n; i++)
printf("%f\n", a[i]);
return 0;
}
Not that I disagree with your code, but it seems like this library uses a modified version of c++, not c/c++.
Zorrito
void gcd(Ptr<Int> p, Ptr<Int> q, Ptr<Int> r)
{
Int a = *p;
Int b = *q;
While (any(a != b))
Where (a > b)
a = a-b;
End
Where (a < b)
b = b-a;
End
End
*r = a;
}
int main()
{
// Construct kernel
auto k = compile(gcd);
// Allocate and initialise arrays shared between ARM and GPU
SharedArray<int> a(16), b(16), r(16);
srand(0);
for (int i = 0; i < 16; i++) {
a[i] = 100 + (rand() % 100);
b[i] = 100 + (rand() % 100);
}
// Invoke the kernel and display the result
k(&a, &b, &r);
for (int i = 0; i < 16; i++)
printf("gcd(%i, %i) = %i\n", a[i], b[i], r[i]);
return 0;
}
Zorrito
void gcd(Ptr<Int> p, Ptr<Int> q, Ptr<Int> r)
{
Int a = *p;
Int b = *q;
While (any(a != b))
Where (a > b)
a = a-b;
End
Where (a < b)
b = b-a;
End
End
*r = a;
}
int main()
{
// Construct kernel
auto k = compile(gcd);
// Allocate and initialise arrays shared between ARM and GPU
SharedArray<int> a(16), b(16), r(16);
srand(0);
for (int i = 0; i < 16; i++) {
a[i] = 100 + (rand() % 100);
b[i] = 100 + (rand() % 100);
}
// Invoke the kernel and display the result
k(&a, &b, &r);
for (int i = 0; i < 16; i++)
printf("gcd(%i, %i) = %i\n", a[i], b[i], r[i]);
return 0;
}
This is one of the examples.
Zorrito
void gcd(Ptr<Int> p, Ptr<Int> q, Ptr<Int> r)
{
Int a = *p;
Int b = *q;
While (any(a != b))
Where (a > b)
a = a-b;
End
Where (a < b)
b = b-a;
End
End
*r = a;
}
int main()
{
// Construct kernel
auto k = compile(gcd);
// Allocate and initialise arrays shared between ARM and GPU
SharedArray<int> a(16), b(16), r(16);
srand(0);
for (int i = 0; i < 16; i++) {
a[i] = 100 + (rand() % 100);
b[i] = 100 + (rand() % 100);
}
// Invoke the kernel and display the result
k(&a, &b, &r);
for (int i = 0; i < 16; i++)
printf("gcd(%i, %i) = %i\n", a[i], b[i], r[i]);
return 0;
}
Huh, I got rid of the r's in this example and replaced *r=a; with *p=a;, and it successfully changed array a. In that case, I have no idea why I'm having trouble with my project.
Anonymous
Anonymous
?
Anonymous
Zorrito
Or you have to iterate over p and q elements?
I have to iterate it over all elements (in my case, it's 384 elements in each array). But the kernel is supposed to be able to do the iteration automatically, by design. The library is set up so that it does the same instruction in batches of 16 (times the number of QPUs used in the RPi's GPU.
Anonymous
Sanjay
Anonymous
I am doing nazi things with CUDA right now xd
Sanjay
😘
Anonymous
Sanjay
what do you need
I wanted to Import stock data to text file from XML, Json what is the easiest way ?
Zorrito
Yeah, is like CUDA
Hmmm maybe I should do a little more research into CUDA and see how it compares. I might get some questions answered that way.
Anonymous
Sanjay
Sanjay