I'm using structure as follows.
struct domain_data
{
int *no_h_domains,
*no_v_domains,
*domain_hsize,
*domain_vsize,
*domain_hstep,
*domain_vstep;
struct domain_pixels
{
int dom_x, dom_y;
double sum,sum2;
int sym;
} ***pixel;
} domain;
But when I try
domain.pixel= (struct domain_pixels ***) malloc(i*sizeof(struct domain_pixels **));
then it gives following errors.
error C2440: '=' : cannot convert from 'domain_pixels ' to 'domain_data::domain_pixels'
and
a value of type "domain_pixels *" cannot be assigned to an entity of type "domain_data::domain_pixels *"
But the same code is executed perfectly fine in win32 application.
Can anyone tell me, whether I can do this in opencl? if yes then how?
The problem is not in the structure of structure, the problem is in the pointers and triple pointers of your struct.
No pointers are allowed to be passed in OpenCL.
Even without that it will never work, since malloc is not allowed in OpenCL.
Please read a guide and a tutorial, before trying to copy-paste a monster C code expecting it to work directly.
It should be doable using OpenCL 2.0 & SVM with Fine-Grain buffers.
Intel is planning to start SVM support with BDW.
When I created another OpenCl project and copied same code over there, then that error is removed ! So thanks everyone for their reply!
Related
I'm writing a Linux filesystem driver, and found this code in a tutorial. From there, I came across this modified version of the previous code, which makes it compile on 3.x kernels. However it seems that again the filesystem API has changed, and one of the functions (inode_init_owner) takes a new parameter. The new signature of this function (in linux/fs.h) is:
void inode_init_owner(struct user_namespace *mnt_userns, struct inode *inode,
const struct inode *dir, umode_t mode);
This mnt_userns parameter isn't given in the example code, and I can't seem to find any documentation for this function online whatsoever. I tried passing NULL for it, in case it would then just ignore it and revert to previous behaviour, but unsurprisingly this led to a crash (dereferencing NULL pointer).
What should this parameter be set to? What does it even mean? Thanks in advance :)
I've found a solution to this, though I'm not sure if it's the correct one.
inode_init_owner(sb->s_user_ns, root, NULL, S_IFDIR | 0755);
It seems that the superblock has a namespace field which I can use and everything works. This does the trick, but I still don't really understand it :)
I have a few logging functions that I commonly use for different Arduino programs. Since I use them so much, I decided to try to make a custom library for them. Unfortunately, the compiler crashes at the header file with the error:
unknown type name 'String'
I'm a bit confused as to why this is happening because I am including the standard Arduino libraries (which I believe should contain the String class) at the top of my header. Here's the whole thing:
#ifndef logging_h
#define logging_h
#include "Arduino.h"
void logEvent(String msg);
void debugOut(String msg);
void errOut(String err);
void document(String parameter, float value);
#endif
I reinstalled the Arduino IDE (1.0.5) so I think I should have the most recent standard library. If anyone has some suggestions I would really appreciate it.
(This answer is based on our discussion in comments.)
The problem was that the source file for your library was named *.c. That caused the compiler to treat it as C code instead of C++, which means it couldn't handle classes/objects (such as String).
Naming the file *.cpp instead lets the compiler treat it correctly as C++ code.
I had same issue yesterday. The code you included in your question should be your .h file, isn't? My question is: is your library written in C or in C++?
I assume you use C code.
You can't import code from in a user C library with the Arduino IDE. The reason is that use C++ code, and it can't be called from your C library.
Solution: rewrite your library in C+, it's not too difficult.
You can find a lot of help on google on how to write library in C++. You can also check my example at https://github.com/romain-viollette/AverageFilter/
best regards,
i am trying to Print some data in wxstring using printf function but its crashing in run time in LINUX but not in windows
here is my code:
wxString str1,str2;
str1 = "Elements";
str2.Printf( _U("%s"),str1);
This is working in windows but not in linux , if i change it below its working in linux also
str2.Printf( _U("%s"),str1.c_str());
why its not taking str1 as argument.
Note:This sentence i am using throughout the workspace is there any common way to do this in linux instead of changing in all places
The only "fix" is to upgrade to wxWidgets 3.0 where wxString::Printf() and other similar functions are (pseudo) variadic templates and so do work correctly with objects and not only raw pointers. In wxWidgets 2.8 they are variadic functions and, according to the language rules, can't work with the objects and no, there is no way around this.
This help clarify you:
The following code:
wxString str;
str.Printf(wxT("My string is %s"), wxString("whatever"));
does not work. Unfortunately, it may seem to work fine under Windows because of a compiler quirk there but passing a wxString object to a function taking a variable number of arguments such as Printf() is undefined behaviour in C++. Accordingly, it will simply crash under most platforms but may even "work" on some of them.
You must use c_str() to make the above code work, i.e. write this instead:
wxString str;
str.Printf(wxT("My string is %s"), wxString("whatever").c_str());
Note that g++ should give you an error when passing an object to a vararg function like this -- another reason to compile your code with g++ even if you normally use another compiler.
I've been using CGSPrivate.h for cocoa development under MacOSX for a while. I'm now using it under Lion (10.7.x), and it turns out that the CGSCStringValue() function described in that file no longer exists under that OS version.
I want to make use of the functionality of CGSCStringValue() -- i.e., converting a CGSValue to its associated char* when appropriate -- and I'm wondering if anyone knows how that function is actually implemented.
I've tried various forms of casting of the CGSValue, but to no avail. So could anyone point me to some documentation or actual cocoa code that runs in 10.7 which will take a CGSValue that's associated with a string as input and return its char* equivalent?
Thanks in advance.
It's implemented by checking the type (to make sure it's really a CFString) and calling CFStringGetCString(). You can do that yourself, there is no real need for CGSCStringValue.
I'm converting the header files of a C library to D modules, and was wondering how I should handle C strings.
Using DMD 1, this works:
void f(char* s); // Definition for C library's function.
But using DMD 2 (which I personally use, but I would like the modules to work for both) strings are const, so to get the same code using the modules to work requires
void f(const(char)* s); // Definition for C library's function.
What should I do? Just use char* and make the 'client' code make the strings mutable somehow? Or modify the type depending on the version of the compiler compiling the code? If the former, what's the best way to make them mutable? I thought .dup would do it, but the compiler wasn't having a bar of it. If the latter, how would I go about doing it? I tried this:
version (D_Version2) {
alias const(char)* charptr;
} else {
alias char* charptr;
}
void f(charptr s);
But alas, the DMD 2 version isn't valid code for DMD 1, and all code in version blocks must be valid code for the compiler compiling the code, even if the code wouldn't be included in the resulting executable. So currently the code compiles in both, but you have to modify the alias first which, as you can imagine, isn't ideal.
You can use the mixin construct to use language-version-specific code that isn't valid in all versions. Example:
static if(version_major<2)
{
alias char* charptr;
}
else
{
mixin("alias const(char)* charptr;");
}
Regarding your actual question, I would suggest doing the same as when interfacing C libraries with C++ - define a type that's const(char)* for D2 and char* for D1, but only use it when appropriate (for example, if a function takes a char* for a buffer to write to, it probably wouldn't be appropriate to name const(char)* something as generic as "charptr"). LPCSTR could work ;)
I didn't understand the "What's the best way to make them mutable" question.
Don't use mixins for this, it's the wrong tool for the job. What you really need is the 'version' statement, you can read about it in the Conditional Compilation page here: http://www.digitalmars.com/d/2.0/version.html
It won't compile / look at code that is for a different version. This allows to build different code for different D versions, or different OS's, different whatever.
Mixins probably works, but it's a heavy tool, doesn't have highlighted code (inside the quotes) and is just overly complicating things. The version statement is perfectly suited for this problem.