How to do a VHDL "typedef" - typedef

I want to "create" a type "my_type", which is a std_logic_vector(...), like this C/VHDL fake code:
typedef std_logic_vector(CONSTANT downto 0) my_type.
"type" does not allow you to do it with std_logic_vector(...), only with array, and "alias" uses only valid types, you can't create a type with it.
So how to do it?

You need subtype
subtype foo is std_logic_vector(7 downto 0);

Related

How to rename an Ada constant defined in the private part

I want to rename a constant in the public part of a package (the original name is deprecated) that is defined in the private part. I tried this but GNAT says:
full constant declaration appears too late
package Sample is
type The_Type is private;
My_Constant : constant The_Type;
My_Renamed_Constant : The_Type;
private
type The_Type is ...;
My_Constant : constant The_Type := ...;
My_Renamed_Constant : The_Type renames My_Constant;
end Sample;
Is there a reason you want a rename instead of (say)
function My_Renamed_Constant return The_Type;
which simply returns My_Constant in the package body?
Functionally identical... and should inline if you're worried about speed.
Later in the deprecation process, make My_Renamed_Constant the constant and My_Constant the function instead. Then, when you think you're ready to retire it, have function My_Constant raise Program_Error or a custom exception indicating "using deprecated constant" to catch any usage you missed.
You probably don’t need to use a renaming; would this do? (this may depend on exactly what the full declaration of The_Type is in your case)
package Sample is
type The_Type is private;
My_Constant : constant The_Type;
My_Renamed_Constant : constant The_Type;
private
type The_Type is new Integer;
My_Constant : constant The_Type := 42;
My_Renamed_Constant : constant The_Type := My_Constant;
end Sample;

'transform' is not a member of 'object'

I'm having a problem with shooter script. Unity in this section shows me the following error:
'transform' is not member of 'Object'
I tried to repair it, but it doesn't work. Any solution?
function ApplyDamage(dmg : float, hit)
{
hit.transform.SendMessage("Damage",dmg);
}
The most common error here is to assume that a generic Object is a GameObject one (that is, a subtype).
I would try one of these two approaches:
1) Defining hit as a GameObject directly in the parameter's definition:
function ApplyDamage(dmg : float, hit : GameObject)
{
hit.transform.SendMessage("Damage", dmg);
}
2) Accessing the gameObject component of it:
function ApplyDamage(dmg : float, hit)
{
hit.gameObject.transform.SendMessage("Damage", dmg);
}

Unable to load a library in MATLAB

I have written a very very simple program in Visual C++ 2008 SP1.
It just adds up two numbers.
The DLLTest.cpp is:
#include "DllTest.h"
__declspec(dllexport) double Add(double a, double b)
{
return( a + b );
}
And DllTest.h is:
#ifndef _DLL_TEST_H_
#define _DLL_TEST_H_
#endif
__declspec(dllexport) double Add( double, double);
I build the DLL using Visual C++ 2008. When I try to load the library using loadlibrary, I get the following error:
??? Error using ==> loadlibrary at 422 Building DllTest_thunk_pcwin64 failed. Compiler output is:
DllTest_thunk_pcwin64.c C:\Users\Admin\Desktop\DllTest.h(5) : error
C2054: expected '(' to follow 'EXPORTED_FUNCTION'
C:\Users\Admin\Desktop\DllTest.h(5) : error C2085: 'Add' : not in
formal parameter list DllTest_thunk_pcwin64.c(40) : error C2085:
'int8' : not in formal parameter list DllTest_thunk_pcwin64.c(41) :
error C2085: 'uint8' : not in formal parameter list
DllTest_thunk_pcwin64.c(42) : error C2085: 'int16' : not in formal
parameter list DllTest_thunk_pcwin64.c(43) : error C2085: 'uint16' :
not in formal parameter list DllTest_thunk_pcwin64.c(44) : error
C2085: 'int32' : not in formal parameter list
DllTest_thunk_pcwin64.c(45) : error C2085: 'uint32' : not in formal
parameter list DllTest_thunk_pcwin64.c(46) : error C2085: 'int64' :
not in formal parameter list DllTest_thunk_pcwin64.c(47) : error
C2085: 'uint64' : not in formal parameter list
DllTest_thunk_pcwin64.c(48) : error C2085: 'voidPtr' : not in formal
parameter list DllTest_thunk_pcwin64.c(49) : error C2085: 'string' :
not in formal parameter list DllTest_thunk_pcwin64.c(51) : error
C2082: redefinition of formal parameter 'EXPORTED_FUNCTION'
DllTest_thunk_pcwin64.c(51) : error C2143: syntax error : missing ';'
before 'type' DllTest_thunk_pcwin64.c(52) : error C2085:
'EXPORTED_FUNCTIONdoubledoubledoubleThunk' : not in formal parameter
list DllTest_thunk_pcwin64.c(52) : error C2143: syntax error : missing
';' before '{'
I want just to load a simple program, written in Visual C++, in MATLAB. How can I fix this problem?
Thanks for considering my question.
I found the problem. Actually, there were two problems:
1) The MATLAB is 64 bit but I made 32-bit DLL and I had to change the settings in Visual Studio to make 64-bit DLL.
2) It seems the compiler that MATLAB uses for loading the DLL, has problem with 'extern "C"' command. So, I changed the header like this:
#ifndef DllTest_h
#define DllTest_h
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
__declspec(dllexport) double Add( double, double);
#ifdef __cplusplus
}
#endif
#endif
And Finally it worked.

Unable to get data in an object in .drl file

I have two rules in my .drl file
rule "Monitor"
when
s : Test1( type == Test1.X )
n : Test123()
then
n.monitor();
drools.setFocus("Rules");
end
rule "Utilization"
agenda-group "Rules"
when
s : Test1( type == Test1.X , newValue > oldValue )
n : Test123()
then
//Do something
end
monitor() is a method in the class Test123, and this method sets values to some variables in the class Test1, by using Getters and Setters. And this method returns an object 'object'. In my second rule I want to compare values (newValue > oldValue) in the object 'object'. How can I perform this operation.
You can save the old value in global variable and compare with it in second rule.

Is there a way to add new items to enum in Objective-C? [duplicate]

I wonder whether it is possible to add/append another item to an existing enum type (part of a framework)?
Something like this: We have the enum type
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
} UIModalTransitionStyle;
Now I want to append or add to this set an item like UIModalTransitionStyleCoverVerticalFlipped.
Can something like this be accomplished?
You can force new element to have the same type as the enum, but you can't extend it in a subclass.
header file:
extern const UIModalTransitionStyle UIModalTransitionStyleCoverVerticalFlipped;
implementation file:
const UIModalTransitionStyle UIModalTransitionStyleCoverVerticalFlipped = 10;
Make sure to give some space in case the framework is extended, so that you don't have conflicts. This is a bit of a hack, but it will get rid of compiler errors and warnings.
To do it, you have to modify the original type definition to include the new value:
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
UIModalTransitionStyleCoverVerticalFlipped
} UIModalTransitionStyle;
Otherwise, you can take a chance on its not working, and define it separately:
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
} UIModalTransitionStyle;
typedef enum {
UIModalTransitionStyleCoverVerticalFlipped =
UIModalTransitionStylePartialCurl + 1
} ExtendedUIModalTransitionStyle;
A variable that could hold the original enumeration will usually also work perfectly fine when/if you assign the new value as well (in a typical case, it'll just be an int) -- but it's not guaranteed. At least in theory, the implementation can/could assign few enough bits to hold that enumeration that it adding more values this way wouldn't work. It could also do range checking so assigning any out of range value wouldn't be allowed. Neither of these is at all common, so from a practical viewpoint it's probably not a problem -- but from a theoretical viewpoint, nothing really guarantees that code like this will work.
Maybe this can help you:
typedef NS_ENUM(NSInteger, BaseType) {
BaseTypeCase1,
BaseTypeCase2,
BaseTypeSize
};
typedef NS_ENUM(NSInteger, SubType) {
SubTypeCase1 = BaseTypeSize,
SubTypeCase2
};
Now you can switch on SubType knowing the values are unique.
If you don't have access to BaseType, you could set SubTypeCase1 to BaseType's last item + 1.
Downside is, you can't declare a method that takes a SubType and pass to it a BaseType without getting a compiler warning. So you need to declare your methods to take NSIntegers in order silence that warning.
Also, it feels weird when you need to declare a parameter of SubType and be able to pass in a BaseType.
To do this you have to update the Enum declaration to include UIModalTransitionStyleCoverVerticalFlipped this values as well
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
UIModalTransitionStyleCoverVerticalFlipped
} UIModalTransitionStyle;
so UIModalTransitionStyleCoverVerticalFlipped will be equivalent to integer constant 4
whereever you use any string constant from Enum dec. corresponding constant value get replaced so it is used to constraint the variable to hold only specified set of values only(i.e. 0 to 4) in above mentioned case