Linux device driver application - linux-device-driver

In my device driver I use
write_Parport_data(struct parport *p, unsigned char data);
In my application, I have to create variable of type struct parport and assign the first element to a value.
such as:
struct parport strApp;
strApp.base = 0x378; // Statement 1
Then:
write_Parport_data(&strApp, 0xff);
gcc compiler error about statement 1
error: invalid use of undefined type 'struct parport'
Even if I include in my application #include
I get the same error.
Even if I use insmod, the mknod to make the driver ready, still compiling the application will give the same error. How my application should use struct parport, what is missing?
Thanks

Are you sure you are including linux/include/linux/parport.h? And giving the compiler the path in the compilation? In other words, are there other instances of defining a var with the parport structure that does not get a compiler error?

Where you have defined this structure ? You should include that header.
You should include that file which has definition of your struct parport
If you have defined that structure in C file, then you should extern that struct definition in header file and include that header file.

Related

iOS Metal Unknown type name 'simd_half3'; did you mean 'simd_char3'?

I'm trying to experiment with using smaller data structures to store Metal vertex data. The Particle struct is shared between Swift and Metal, but am getting the following error:
Unknown type name 'simd_half3'; did you mean 'simd_char3'
What do I need to import to get over this compilation error?
(The same struct compiles when pasted directly into the metal shaders file). Is it because there is no half type in Swift?
ShaderTypes.h - C Header file
#ifndef ShaderTypes_h
#define ShaderTypes_h
#include <simd/simd.h>
struct Particle {
simd_float3 floatTuple; // works fine
simd_char3 charTuple; // works fine
simd_half3 halfTuple; // Unknown type name 'simd_half3'; did you mean 'simd_char3'
};
#endif /* ShaderTypes_h */
All these types are defined in the same file, and using the command-click, I can jump to their definition (so the editor knows about the types), but I still get that build error.
I think the problem is that there was no Half type in Swift until recently (there is Float16 now with Xcode 12). But there still seems to be no simd_halfN, at least it's not listed in the simd/vector_types.h header.
The easiest option for you is probably to just work with float for now.
There is a half type in Swift, it's Float16. As for simd types, in Swift, simd_floatN is just a typealias for SIMDN<Float>.
It's defined like this: public typealias simd_float3 = SIMD3<Float>
Since Swift supports Float16 now for half precision floats, you can just pass it to SIMDN generic, since it's defined as following (SIMD3 for example)
#frozen public struct SIMD3<Scalar> : SIMD where Scalar : SIMDScalar
and there's an extension
extension Float16 : SIMDScalar
to make Float16 conform to SIMDScalar
So you can use SIMDN<Float16> and if you want you can probably even typealias it in your code.

How to access properties/member of struct pointer in Swift

I am messing around with Mach-O Headers and dyld and came across this function _dyld_get_image_header that returns a pointer to the mach header of a dynamic library.
I thought I might be able to access the Mach-O segments of dynamic libraries through this pointer following this article. However, I am not able to access the properties of the Mach-O Headers and am getting errors . In the Swift code below, I attempted to access the ncmds or load command property of the struct and was met with an error:
var currentLibrary = 0
// Gets Pointer to Mach Header of First Dynamic Library, Index 0
let libHeader = unsafeBitCast(_dyld_get_image_header(UInt32(currentLibrary)), to: UnsafePointer<mach_header_64>.self)
print(libHeader.ncmds)
Error:
Value of type 'UnsafePointer<mach_header_64>' has no member 'ncmds'
It's similar to c, where you would use the -> operator (libHeader->ncmds), requivalent to (*libHeader).ncmds. That is, first your reference the pointer to get to the mach_header_64 value, then you access its ncmds field.
In Swift, it's the exact same idea, with different syntax: libHeaver.pointee.ncmds

Unknown type error in .mm file

I have a .mm file called A.mm, and in it I import B.hpp file, I use the struct C in B.hpp.
But the Xcode build will report unknown type error, it demands me to add the namespace before the C class.
If I click go to definition of C class it can jump to the right place in B.hpp. So I wonder can I do something to avoid adding long namespace prefix?

Why is my 'kMyConstant' macro redefined?

In my app delegate class I define a constant like so:
#define kSomeConstant #"My_Constant_Value"
I then want to make use of this constant in another viewController so I defined it again exactly as above. I now get the message:
'kSomeConstant' macro redefined
Why is this the case? Is there some other way I can access the constant?
Simply redefining the constant (ie : same constant name). Choose another name, or define it just one time in a header file to access the constant value every where you import that header.
It's likely been defined twice among the sources which are visible to the compiler. the compiler may tell you where the previous definition is if you look into the message in more detail.
To avoid this problem entirely, declare your NSString constants like this:
file.h - declaration:
extern NSString* const kSomeConstant;
file.m/mm - definition:
NSString* const kSomeConstant = #"My_Constant_Value";
Then when you need to use the constant, just #include "file.h".
The compiler has encountered two definitions of the macro. Probably you defined it in a header file and then defined it again in a .m file.
If you can't figure out where the two definitions come from, try preprocessing the file with the error (in Xcode 4.2 this is under generate output in the product menu). You can then do a search for kSomeConstant and that should tell you where it comes from.

Error: 'class name' redeclared as different kind of symbol?

I was facing the same error as asked in this question
I overcome with this error by solution of declaring class ahead of time in my .h file with the class parameter
I am having FFTBufferManager.h and FFTBufferManager.cpp file and using it in HomeView.h and HomeView.mm file
class FFTBufferManager,CAStreamBasicDescription,DCRejectionFilter;
But now I am having error as
#include "FFTBufferManager.h"
#include "aurio_helper.h"
#include "CAStreamBasicDescription.h"
class CAStreamBasicDescription,FFTBufferManager; //here it shows this error
EXpected Unqualified-id befor ',' token
#interface HomeView
{
FFTBufferManager* fftBufferManager;
//it shows erros
EXpected Unqualified-id befor ',' token
ISO c++ forbids declaration of FFTBufferManager with no type
}
#property FFTBufferManager* fftBufferManager;
//shows error
'FFTBufferManager' is not a type
I'm gathering you're using both C++ and Objective-C.
I'd suggest renaming all your .cpp and .m files in which Objective-C and C++ code are meeting to use the extension .mm - this tells the compiler to use "Objective-C++" rules, and will stop a lot of compiler troubles.
Also, it seems CAStreamBasicDescritpion is a C++ class - you'll have to forward-declare it with class CAStreamBasicDescritpion;, not #class CAStreamBasicDescritpion; (note, no "at" sign) - the second form is only for forward-declaring Objective-C classes. This I suspect is the root cause of the particular error you have observed.
EDIT in response to comment: I'm not sure about your first new issue - that should work fine so long as both FFTBufferManager and CAStreamBasicDescription are C++ classes. As to your second one, depending on where exactly that line of code is (CAStreamBasicDescription thruFormat;) you may need to include the header rather than just the forward-declare: you're declaring an instance of CAStreamBasicDescription here, and the compiler needs to know its structure to do so.
You can't declare more than one class at a time.
Change your declarations to
class CAStreamBasicDescription;
class FFTBufferManager;
The compiler is looking for an unqualified-id because it believes that you're declaring a variable of type CAStreamBasicDescription, so it expects a variable name where you gave it a comma.
Looks like you are trying to create a class that already exists in one of the Cocoa frameworks.