Questions tagged [compiler-directives]

Compiler directive is a language construct that specifies how a compiler (or assembler or interpreter) should process its input.

Compiler directive is a language construct that specifies how a compiler (or assembler or interpreter) should process its input.

125 questions
2
votes
2 answers

Is there a compiler directive to replace part of a constant

I'm working with embedded C for a microcontroller right now and I find that sometimes there are several peripherals that differ only by a single letter (for example UARTA, UARTB, etc). The code for each peripheral is often times identical except…
Joel B
  • 12,082
  • 10
  • 61
  • 69
1
vote
2 answers

Pass by name for macro arguments

For functions, we can use pass by name as below: function void xyz(string x,int y); $display(x,,y); endfunction initial begin xyz(.x("Hi"),.y(2)); end Now, I have a macro like below: `define XYZ(name,number) \ int num; \ …
1
vote
1 answer

SwiftUI compiler directives trigger "Cannot infer contextual base" error for following statements

I have a SwiftUI View for a watchOS / iOS app in which I use the #if os(xxxOS) compiler directive to select between a watchOS specific View or an iOS specific View to provide the content for the the OSCommonView body var. Both the watchOS and iOS…
djmlewis
  • 273
  • 4
  • 7
1
vote
1 answer

How to assert size of `usize` to drop support for incompatible platforms?

Problem I've just caught my self writing dynamic assertion that depends on a constant usize::MAX. I wrote: u128::try_from(letters.len()) .expect("No suppor for platform with `max pointer value` >= 2**128.") where letters.len() is an instance…
Sir
  • 337
  • 1
  • 7
1
vote
2 answers

{$WARN DUPLICATE_CTOR_DTOR OFF} gets deleted from Dpk file

I need to turn off this compiler warning because I don't intend to make my library compatible with C++. If I put the compiler directive in the PAS file that generates the warning, it is ignored. People on the mighty internet say that {$WARN…
Gabriel
  • 20,797
  • 27
  • 159
  • 293
1
vote
1 answer

Operating System Directive in Delphi Prism

Since I am writing a program that will eventually run on Windows and Linux environment compiled from the same project files, I wanted to test and see how well the Operating System directives are. So, I wrote a sample code. The code seems to run…
ThN
  • 3,235
  • 3
  • 57
  • 115
1
vote
1 answer

Why only include header files (.h) but not the source file (.c) in the directives?

How does the compiler know which source file is the one I am including? Does it work as long as the name of the header and source file are the same? For example, the header file example.h refers to example.c and so including example.h would be…
1
vote
0 answers

Compiler says variables declared within compiler directive doesnt exist

Suppose I have this code (all in the same class): #if CONDITION private static readonly string firstName = "First Name"; #endif string GetName(){ #if CONDITION return firstName; #endif return "Second Name"; } It is…
Daniel
  • 7,357
  • 7
  • 32
  • 84
1
vote
2 answers

Can someone explain hard ilogical bug on C use of #define UMAX (a, b) ((a) > (b) ? (a) : (b)) directive, that returns lower value, in 2 compilers

I'm trying to identify the reason of a bug that happens on a MUD c code base. Where the use of the #define UMAX(a, b) ((a) > (b) ? (a) : (b)) , is used to return the max of two values. It sometimes returns the lower value, and even debuging I…
1
vote
3 answers

Compilter Directives - Suggestion - Run code in Debug mode only

I need to Log messages only when application is running in debug mode. I have found 2 ways: First: Need to write 3 lines everywhere when logging is needed. But, Logger statement is disabled at compile time only which is exactly I need. Logger.Log…
Let me Ask
  • 1,029
  • 1
  • 8
  • 33
1
vote
0 answers

How do I write test-only code in Production code using #ifdef in C++?

NOTE: I think this is quite basic, please point me in the right direction if this is already answered. I did look online but surprisingly unable to find the answer, I could be using wrong words to search. I felt I should be able to do by defining…
1
vote
3 answers

Does C preprocessor directives recompute each time?

I have this line of code: #define ALPHABET_SIZE 'z' - 'a' + 1 When I hover over ALPHABET_SIZE anywhere in my code it tells me that it expands to 'z' - 'a' + 1. So I wondered if this expression has to be recomputed each time I use ALPHABET_SIZE in…
Algo
  • 178
  • 7
1
vote
1 answer

Recognise #define compiler directive in fortran with ctags

I would like to configure ctags to recognize compiler directives in a fortran code. More specifically, I would like to match the following vim search result /\v[ \t]*#define[ \t]+([-[:alnum:]*+!_:\/.?]+)/ where \v induces the very magic level (see…
Josja
  • 131
  • 7
1
vote
0 answers

How to create custom compile directives in swift

I have a generic function that fetches from DB objects based on a given type and filter: class Employee: Object { @objc dynamic var id: String = UUID().uuidString @objc dynamic var hardWorking = false } class Student:…
Iosif
  • 353
  • 2
  • 15
1
vote
0 answers

Delphi $E directive

I am trying to automatically generate the extension of my DLLs to get FileName.$(Platform).DLL. Supposedly I can use {$E ext} to set the extension to FileName.ext, and I want FileName.ext.dll The problem is if I use {$E ext} I get FileName.ext as…
Nani
  • 113
  • 5
1 2 3
8 9