I'm working on a project based on MSP430 microchip, using IAR compiler. Here is the simplified problem:
In my project I have 3 files:
In clock.h:
#define MCLK_8MHZ
void clk_init(void);
In clock.c:
#include "clock.h"
void clk_init(void)
{
#ifdef MCLK_8MHZ
#define delay_ms(x) __delay_cycles((long)(1000000*(double)x/1000.0))
#endif
#ifdef MCLK_12MHZ
...
#endif
}
In main.c:
#include "clock.h"
clk_init();
delay_ms(5);
And the compiler would say function "delay_ms" declared implicitly
I think it mistook the delay_ms() as a function instead of a macro. Sure I could define it as a real function. But I thought it would damage the accuracy of time controlling.
How to solve this problem?
Do you need quotes around your include in main.c like:
#include "clock.h"
?
If that is your only warning, it's something else.
Related
I'm trying to use a preprocessor macro in my custom shader so it performs a different step if it's in the Unity Editor:
#if defined(IS_UNITY_EDITOR)
// something
#else
// other thing
#endif
To achieve this, I'm trying the Shader.EnableKeyword() method in a MonoBehavior:
if (Application.isEditor) {
Shader.EnableKeyword("IS_UNITY_EDITOR");
}
However, it looks like my shader is being compiled before the MonoBehavior can check if it's in the unity editor. I've tried running it on Start(), on Awake(), OnEnable() but the shader never receives the IS_UNITY_EDITOR definition. How can I define IS_UNITY_EDITOR in my shader before the shader is compiled?
Just stumbled upon this doc page that explains how multi compile works. In order to be able to create two branches, I have to tell the compiler I'll be using the IS_UNITY_EDITOR keyword by writing a #pragma multi_compile line:
SubShader {
Pass {
CGPROGRAM
#pragma multi_compile __ IS_UNITY_EDITOR
#pragma vertex vertShader
#pragma fragment fragShader
// ...
The double underscore __ means one version of the shader will have IS_UNITY_EDITOR and the other version will have nothing defined.
Using UE 4.23.1
Basically, i'm following a very simple tutorial.
I've extended multiple base classes, and it seems in ANY of my extensions, the variables for all components (e.g., physics, collision, static mesh, etc) all reset EVERY TIME i do a full project compile.
For instance:
I've extended UStaticMeshComponent with custom functionality (TankTrack). I set the static mesh component, and adjust the Collision to "Simulation GEnerates Hit Events". This sticks, but as soon as i recompile the entire game, EVERYTHING is reverted to its original state. Help!!
Note: This happens on variables I declare (and make UPROPERTY(EditAnywhere)) as well as those defaulted to that component type (e.g., Physics, collision, etc)
Here is an example with a UActorComponent called "Grabber". Only the .h file should matter if the issue is with blueprint?
If i change maxPickupWeightKg, then recompile, the change does NOT persist.
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "PhysicsEngine/PhysicsHandleComponent.h"
#include "Grabber.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class FPSExample_API UGrabber : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UGrabber();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
/// Grabber functions and variables
UPROPERTY(EditAnywhere, Category = "Grab Setup")
float maxPickupWeightKg = 50.f;
};
.cpp Constructor is nothing fancy:
#include "Grabber.h"
#include "Math/UnrealMathUtility.h"
#include "CollisionQueryParams.h"
#include "Engine/EngineTypes.h"
#include "Engine/World.h"
#include "Components/ActorComponent.h"
#include "Components/PrimitiveComponent.h"
#include "GameFramework/Actor.h"
#define OUT
// Sets default values for this component's properties
UGrabber::UGrabber()
{
PrimaryComponentTick.bCanEverTick = true;
}
.
.
.
My Hierarchy for the FPS Blueprint this is on:
FirstPersonCharacter(self)
-
CapsuleComponent (This is where all the player meshes are)
-
CharacterMovement
PhysicsHandle
Grabber
Thanks !
I am placing this here because I've had the same issue. After many hours of testing and research, I found this answer in the unreal forums. I hope it helps.
https://forums.unrealengine.com/development-discussion/c-gameplay-programming/1530690-uproperty-value-keeps-resetting-on-every-compile?p=1651757#post1651757
Using 4.25.3 this has still not been fixed. My workaround is to create a child blueprint of the component and use that on my Actor. This way the property values do not get reset when compiling.
Since frameworks do not support bridging headers, how do I import ifaddrs.h into a swift file inside a framework?
Or is there another way to get the devices ip address on the LAN, that will work on both iOS and OS X?
In an app target, a bridging header does the trick. Inside a framework target, things are trickier. Inside Swift code we can only import so called modules. The trick is to define a module map that provides the desired C library resource and make it visible by setting SWIFT_INCLUDE_PATHS inside the build settings (Build Settings->Swift Compiler->Import Paths) to the path of the module map file. There are two methods for doing this:
1) The following allows for a pure swift implementation by exposing the ifaddrs.h interface directly but sadly requires an exact path to the header file, which is not desirable if you're ever going to release your library as open source.
module.modulemap
module ifaddrs [system] {
header
"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/ifaddrs.h"
export *
}
Add to swift code
import ifaddrs
2) The second way is to create an Objective-C class which provides an interface to ifaddrs.h but hides the actual import of ifaddrs.h the source *.m file.
NetworkTools.h
#interface NetworkTools : NSObject
+ (NSDictionary *)getIFAddresses;
#end
NetworkTools.m
#import "NetworkTools.h"
#include <ifaddrs.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <netdb.h>
#implementation NetworkTools
+ (NSDictionary *)getIFAddresses {
NSDictionary *addresses;
// code
return addresses;
}
module.modulemap
module NetworkTools {
header "Obj-C Tools/NetworkTools.h"
export *
}
Add to swift code
import NetworkTools
For more info on how this all works together, check out:
Sample project on Github: https://github.com/danieleggert/mixed-swift-objc-framework
As well as the article about Clang modules: http://clang.llvm.org/docs/Modules.html
You can use NSHost's address or addresses methods.
I get a "unused static function" warning in Eclipse for code that looks like this:
my.c:
static void myfunc(void) { // This line gives unused warning.
printf("in myfunc()");
}
typedef void(* myfunctyp)(void);
#include "my_generated.h"
my_generated.h:
myfunctyp mylist[] = {
myfunc,
0
}
my_generated.h is a generated code so I cannot just put the array in the .c file.
My Questions are:
How can I tell Eclipse to look into the include file so it can accurately determine that the function is used?
If I cannot get #1, how can I add an indicator in the source code to tell eclipse that this particular warning is okay? I am aware that I can change Window->Preferences->Code Analysis -> Unused Static Function configuration to eliminate the error, but I would like something that "sticks" with the source.
[Edit (Addition)]: The function gets called in the main program like this:
mylist[0]();
If I move mylist[] declaration into the .c file, the warning error does not appear.
Here is one solution:
#define MARKASUSED(x) if (0) { x(); }
static void myfunc(void) {
printf("in myfunc()");
MARKASUSED(myfunc)
}
The 'if (0)' should cause the compiler to remove the code with any kind of optimization on so it would not impact runtime at all.
I don't think this solution is ideal, but it meets my immediate needs.
In one of projects I have a file written in ARM assembly that uses NEON to optimize a calculation I am doing it. I also have a file that does the exact same thing except that it is written in C. Currently I just comment out the C functions that are being defined in assembly and just add a
extern void myFunction();
to the C file. What i would like to do is have this in the C file
#ifdef device
extern void myFunction();
#else
void myFunction() {
/* code here */
}
#endif
I would also need something similar in the assembly file but im not sure how to do preprocessor directives in ARM assembly.
So to sum all this up im looking for a preprocessor definition that tells me what device im am building for and a way to use preprocessor directives in assembly.
In your C file:
#if defined __arm__
extern void myFunction();
#else
void myFunction() {
/* code here */
}
#endif
In your assembly file:
#if defined __arm__
/* code here */
#endif
(Xcode applies the C preprocessor to .s files as well).