Skip to main content

All Questions

0 votes
1 answer
144 views

Is a C compile-time constant applied the same as a preprocessor define variable after compile time? [duplicate]

What I'm asking is does a C const variable defined in such a way that its value is known at compile time: const int num = 3; int main(){ int arr[num]; } act in the same way as a preprocessor ...
Ethan's user avatar
  • 167
1 vote
1 answer
61 views

Conditional inclusion: numeric value for the character constants: within #if/#elif vs. without #if/#elif: why matching is implementation-defined?

Case A: C11, 6.6 Constant expressions, Semantics, 5: If a floating expression is evaluated in the translation environment, the arithmetic range and precision shall be at least as great as if the ...
pmor's user avatar
  • 6,179
0 votes
0 answers
48 views

how to convert a #defined item to a string in c++? [duplicate]

Suppose I have defined an item #define CLASSNAME MyClass and I then want the preprocessor to generate a string constant "MyClass" e.g std::string str("MyClass") I cannot of ...
elena's user avatar
  • 291
-2 votes
1 answer
356 views

Trying to replace #define with const does work

So I originally wrote my program using #define since I know it happens as a preprocessor, but my teacher commented that I should use const. I tried replacing #define in my code but it just broke it ...
BENJAMIN WEED's user avatar
0 votes
0 answers
35 views

what's the use case of define preprocessor directive? [duplicate]

I am writing a c program consisting of 5 modules, each with an associated header file where functions prototypes are written. Only, I have a c file/header pair that I only use for defining constant ...
Balocre's user avatar
  • 175
0 votes
2 answers
2k views

Can I #define a constant solutionwide within c# code without project settings?

I know this was aksed and answered a a couple of times e.g. Solution-wide #define, Is There anyway to #define Constant on a Solution Basis? and How to define a constant globally in C# (like DEBUG). ...
derHugo's user avatar
  • 89.6k
-1 votes
1 answer
3k views

Best way to declare a constant string in C [duplicate]

I have a string: "The world is a beautiful place to live in.". I have two source files and a global header file. I can access the string in two easy ways:- Declaring and defining a constant ...
pkthapa's user avatar
  • 1,061
1 vote
3 answers
4k views

Evaluate all macros in a C++ header file

I have a requirement to build an automated system to parse a C++ .h file with a lot of #define statements in it and do something with the value that each #define works out to. The .h file has a lot of ...
Techrocket9's user avatar
  • 2,056
1 vote
4 answers
164 views

C char of string to array

I have 2 defines, one with a string and one with a number.How can i make a const array from the define with the string and the number. There are also some additional constant which should be in this ...
12431234123412341234123's user avatar
0 votes
2 answers
67 views

How to assign const static with an incremental macro?

I am trying to assign an unique value to const static unsigned int members, without having to think about assigning the right values myself (preventing human errors). I've created a minimal solution ...
oddRaven's user avatar
  • 672
1 vote
1 answer
105 views

C++ and Swift Don't Like Each Other

I am trying to use a C++ library named MP4v2 in Swift. It is mostly working in that I can can call some functions, use some classes, etc. I am having trouble with a particular function that returns a ...
Coder-256's user avatar
  • 5,551
0 votes
2 answers
88 views

Is using object-like macros a good way to define global variables?

I've been told by my teacher that the preprocessor command #define is the way to go to declare a global variable. Basically I use the object-like macros #define x 3 to declare x as a global variable....
Claudio Cortese's user avatar
6 votes
4 answers
2k views

How are chained macros resolved in C?

If I want to use preprocessor #define statements for easy definition and calculation of constants and common functions and take advantage of less RAM overhead (as opposed to using const values). ...
aaroncarsonart's user avatar
1 vote
3 answers
3k views

How to pre-define an array in c?

#include <stdio.h> #include <math.h> #define Hey {0.9501, 0.2311, 0.6068, 0.4860, 0.8913, 0.7621, 0.4565, 0.0185, 0.8214, 0.4447, 0.6154, 0.7919, 0.9218, 0.7382, 0.1763, 0.4057, 0.9355, 0....
Reddevil's user avatar
  • 125
4 votes
1 answer
434 views

Why use both anonymous enum and define macros for constants? [duplicate]

Why netinet/in.h defines constants this way? enum { IPPROTO_IP = 0, #define IPPROTO_IP IPPROTO_IP IPPROTO_HOPOPTS = 0, #define IPPROTO_HOPOPTS IPPROTO_HOPOPTS ...
jackhab's user avatar
  • 17.7k

15 30 50 per page
1
2 3 4 5 6