How can I tell the compiler about a variable at compiletime without using a preprocessor directive?

I recently ran into the infamous issue

int n = 5;
int a[n];

The compiler told me it needs a constant size for arrays, so I tried const int n = 5 and but this also didn't work. I threw the kitchen sink and tried static int n = 5 as a local and global variable, and it also didn't work.

The only thing that worked was #define n 5. Is this the only way to do it? Is there ANYTHING outside of preprocessor directives done at compiletime and not runtime?

Thanks!

πŸ‘︎ 13
πŸ’¬︎
πŸ“…︎ Nov 12 2021
🚨︎ report
How to properly pronounce # in preprocessor directives ?

Fairly simple. I've got the awful habit of saying "hashtag define", and I'd like to change that. How do you all pronounce it?

πŸ‘︎ 24
πŸ’¬︎
πŸ‘€︎ u/KrozmaSan
πŸ“…︎ Aug 23 2021
🚨︎ report
Unexpected tokens following preprocessor directive - expected a newline

So when writing an include directive, I accidently added a 0 to the end without noticing:

#include <header>0

And MSVC produced this warning: warning C4067: unexpected tokens following preprocessor directive - expected a newline

To my surprise, I learned that MSVC ignores anything I put at the end of include directives:

#include <header>fsdfsdf

And this works fine. Is this legal in standard C++, or is this just an MSVC quirk? If it's allowed in standard C++, then why?

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/its_Artem
πŸ“…︎ Jun 12 2021
🚨︎ report
I created a brainfuck interpreter written entirely in C preprocessor directives github.com/Ferdi265/prepr…
πŸ‘︎ 2k
πŸ’¬︎
πŸ‘€︎ u/Ferdi265
πŸ“…︎ Jan 25 2020
🚨︎ report
Godot Plugin Development MonoDevelop TOOLS Preprocessor Directive Issue

I'm actually not sure where to write this one, here or somewhere related to Monodevelop. I wanted to post it here anyway. So, I'm following the plugin development section of the documentation. In this section, it uses a conditional preprocessor directive, saying #if TOOLS.

The thing is Monodevelop treats to this section like comment and does not provide intellisense. See this.

So far I've come across this question in Stackoverflow. It's mainly Unity-related question but I kinda-kinda get the answers. It is a conditional compilation (?). The questions mainly touch on DEBUG and RELEASE compilations but here we have something called TOOLS, which is kind of different.

So, I've wanted to hear you guys. Have you encountered this while developing Godot in C# and how did you deal with it? Thanks in advance.


Environment

  • Manjaro 19.0.2
  • Mono JIT Compiler 6.4.0
  • MonoDevelop 7.8.4
πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/erayerdin
πŸ“…︎ Apr 06 2020
🚨︎ report
C++/CUDA any reason to run function in header file and run via preprocessor directive?

Sort of a weird question, but I'm parsing through some c++/cuda code someone else has written and they call a function via #include "theFunction.h" in the middle of their main, where theFunction header file is for all intents and purposes just runs the (cuda) function, e.g.

runFunction<<<BkGd, ThBk>>>(gFval, gIAval);
cudaDeviceSynchronize();

Is there any sensible reason I don't know about to do this via preprocessor directive or is the author just being unconventional here?

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/still_tyler
πŸ“…︎ Jul 02 2020
🚨︎ report
Preprocessor directive to flag code that doesn't get compiled at all, and is only "available" during design time?

I have a view that has a lot of "default" values set (in the empty constructor), but only for the purpose of design. When the code is actually compiled and run, those default values never actually get set because the empty constructor is never called.

I would like to be able to compile my code in such a way that some preprocessor directive tells it not to compile the empty constructor at all. It should be missing from the "compiled" version. I know I can do this using #IF DEBUG, but I don't want it available in my compiled debug code, either.

Is there such thing as a preprocessor directive that will make design-time code disappear on compile?

πŸ‘︎ 11
πŸ’¬︎
πŸ‘€︎ u/Javin007
πŸ“…︎ Jan 26 2018
🚨︎ report
Is it considered bad practice to use preprocessor directives?

I recently learned about the usage of the fpp/cpp preprocessors in gfortran/ifort, which opens up the possibility of interesting new capabilities. In particular, I'm interested in using:

__FILE__
__LINE__

in a logging module, to output the current filename and line number of executing code. However, I'm wondering if this is considered bad practice. This will be a large codebase, so I don't want to sprinkle these in hundreds of places throughout the code and eventually regret it. Any thoughts on this?

πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/surrix
πŸ“…︎ May 01 2018
🚨︎ report
Preprocessor directives in GMS2

After a long hiatus, I'm back with a video on the preprocessor, and how to take advantage of it in GMS2.

https://youtu.be/bt0pZK890KQ

hope you find this useful someday!

πŸ‘︎ 15
πŸ’¬︎
πŸ‘€︎ u/GMWolfTuts
πŸ“…︎ Jul 11 2018
🚨︎ report
PreProcessor Directives (#define values) into a library from a sketch?

Hello, kind of a weird question but one I'm kind of stuck on.

I'm not sure if I'm asking the above questions right, but basically I would like users of libraries I make to be able to configure parts of it using directives, so in the library I can ifdef some logic or functionality so it is completely removed at compile time (or am I understanding this right?)

Passing the the values in the constructor or whatever is too late, I would like chunks of code to be removed while compiling

A basic example would be, if I was working on a library and I wanted to add some debug serial prints, but I only wanted them to happen if the user defined #define LIBRARY_DEBUG true or whatever in their sketch. Then in the library the debug serial prints would be wrapped in a #ifdef LIBRARY_DEBUG and one only get compiled if required.

I tried the above out and the library does not see LIBRARY_DEBUG being defined. From some research online it suggests that the library needs to include a header file that has these things defined, is this the only way around it?

The debug flag example is easily worked around by just making a public property or whatever, as the Serial prints don't use up a lot of memory. But there are some things like DynamicJson buffers suit some boards better than StaticJson buffers and I would like to use one or the other based on a user input.

Some libraries such as FastLED have you change some settings using directives in the sketch and I don't understand how they can do it

Any suggestions?

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/witnessmenow
πŸ“…︎ Feb 14 2018
🚨︎ report
Is it a good idea to use configuration structs over preprocessor directives for tuning behavior?

Honestly, I've a bit of a fear of showing my actual code since the last time I did (long time ago) I got burned pretty badly for it (in my defense, I know now it WAS that awful back then, but still I was a beginner). However, to refine my technique and become a better C programmer, I'm going to go ahead and do so.

The preprocessor, as old, trustworthy and reliable as it is, has it's drawbacks. The main ones being that being forced to use #ifdef preprocessor directives can (and often will) make code harder to read. It comes with the trade-off of not requiring excess memory, but also having those conditionals constant throughout the program. Hence, if you had two version of an object, and you wanted to, say, configure one of them differently from the other, you are unable to do so. The most common alternative I've seen is to add more excess parameters, but that can easily grow out of hand quickly.

Lets say for an example, you have a hash map. A hash map can be a relatively simple data structure, but it can also be fine-tuned for certain usages as well. For example, a normal hash map implementation isn't thread safe, and creating and acquiring/releasing a lock when it is a single-threaded application is an unnecessary performance waste. Hence, most would have a preprocessor #define such as #define MAP_SPINLOCK or #define MAP_MUTEX or something similar to fine-tune it. The issue is that if you wanted, say, 2 maps, one which has higher contention (I.E want to use spinlock) and another for low contention (I.E want to use mutex), or concurrent access (I.E, want to use a reader-writer lock), then it would be impossible using preprocessor macros. What would the solution be, to add more parameter arguments? Then you get stuff looking like [this](https://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85)), which gets HUGE, and also is impossible to modify if you wanted to add another parameter or feature.

"Okay, so how is your solution any better? You just end up with a HUGE struct which needs to be filled out anyway!". This is true, we DO end up with a huge struct (how huge depends on how customizable), however there is ONE huge advantage. I'm targeting C99 and up, so it will not work in C89-mode, however, initializer lists automatically zero-allocate the structure. Not just that, but it also allows you to specify WHICH you wish to fill out. The ones left blank will fall back to a default, simple as that. Arguments which are NEEDED (like

... keep reading on reddit ➑

πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/theif519
πŸ“…︎ Mar 31 2016
🚨︎ report
Preprocessor Directives

Can anyone help me understand these:

#ifndef NEWFILE_H
#define	NEWFILE_H

#ifdef	__cplusplus
extern "C" {
#endif




#ifdef	__cplusplus
}
#endif

#endif	/* NEWFILE_H */

This is from a template C header file. And yes I know I can Google each and find out what they do, but what I am asking is what purpose is it serving in this document? Why are they considered template worthy?

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/Trol0lolol0l
πŸ“…︎ Aug 11 2014
🚨︎ report
Ocaml preprocessor to remove toplevel directives when compiling.

The problem:

For example let the file ls.ml be:

#require "unix" ;;
#require "str" ;;    

let () = 
 Sys.readdir "." 
 |> Array.iter print_endline
;;

Running in batch mode, works:

$ ocaml ls.ml 

However when I tried to compile with the toplevel directives, I got the error:

$ ocamlc -o ls.byte  ls.ml
File "ls.ml", line 2, characters 0-1:
Error: Syntax error

Removing the directives, it works:

(*
#use "topfind" ;;

#require "unix" ;;
#require "str" ;;
*)

let () = 
 Sys.readdir "." 
 |> Array.iter print_endline
;;

Compiling:

$ ocamlc -o ls.byte  ls.ml

Is there any ocaml preprocessor or trick to remove toplevel directives during compilation without change the code ?? I tried to use the trick describe in: OCaml shebang syntax error

$ ocamlc -o ls.byte  ls.ml -pp 'sed "1 s/^#\!.*$//"'
File "ls.ml", line 3, characters 0-1:
Error: Syntax error

And I still get errors. Is there any way to automatically remove the directives when compile without change the source code ???

Seeing the ocamlc man page I found:

> -pp command

> Cause the compiler to call the given command as a preprocessor for each source file. The output of command is redirected to an intermediate file, which is compiled. If there are no compilation errors, the intermediate file is deleted afterwards. The name of this file is built from the basename of the source file with the extension .ppi for an interface (.mli) file and .ppo for an implementation (.ml) file.

Is there any way to use this -pp to remove the directives ???

πŸ‘︎ 4
πŸ’¬︎
πŸ‘€︎ u/eniacsparc2xyz
πŸ“…︎ Aug 01 2015
🚨︎ report
Indent C/C++ Preprocessor Directives as regular code?

So, title really says it all, is it in anyway possible? Regex (seems unlikely, at least not so it can handled nested ifdefs), VimL (I think, but I don't know enough to do it myself), etc.?

Yeah, removing 0# from cinkeys and indentkeys mostly prevents it from being placed back in the 0th column, but not if you use = for indenting... And I certainly can't find a way to make it do the indenting...

It's really kind of bugging me that vim doesn't offer a way to do this, simply, as far as I can tell, because really old pre-ANSI compilers required the # be the first character, AND I couldn't (quickly) find an online indenting tool that worked for preprocessor directives.

One last search through the manual finds equalprg and a google search finds GNU indent which at least does indenting after the #, but... not sure how much work that'd take to setup and if I was using more than one machine I couldn't easily recreate my workflow since it would involve trying to install said program.

Though since I've used clang with cs50 (yeah, newbie programmer) I gotta wonder if ClangFormat would be better...

Still thought I'd ask here before doing to much work with external programs and setting them up to do something logical to me...

Hope someone here has a nice simple solution, and in case you do, thanks! :)

πŸ‘︎ 5
πŸ’¬︎
πŸ‘€︎ u/FreeER
πŸ“…︎ Sep 09 2015
🚨︎ report
Windows Phone 7 – Speed Up Development with Preprocessor Directives- Ecofic blog.ecofic.com/?p=862
πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/gcaughey
πŸ“…︎ Apr 13 2012
🚨︎ report
The quickness and efficiency of Preprocessor Directive: "Define," illustrated using addition. [3] [I]

Preprocessor Directives - Difficulty Rating: [3]

This is the first installment of the Proprocessor Directives series.

Difficulty Rating: [2] Length: [I]

In this program we see a potential use of the "#define" preprocessor directive. Using this technique, I get to assign constants that can then be used for the rest of the program. They are read by the program almost immediately and stored in memory. In this example, I have many numbers that are quite lengthy, and instead of repeating them over and over, I get to turn them into very short strings of characters. "n" stands for number in this program. You can see how the amount of typing that I did was miniscule compared to the amount of output that the program did for me. Imagine having to use these numbers hundreds of times, only having to refer to them by "n1" or "n2" every time. Easy!

You can compare the code to the results, uploaded to an image to save you time.

#include <iostream>

#define n1 57.2835

#define n2 59606

#define n3 24

#define n4 9753

#define n5 1273

#define n6 1111

#define n7 89

using namespace std;

int main()

{

cout &lt;&lt; "Hello! Today we see how cool \"preprocessor directives\" can be.\n";

cout&lt;&lt; "Compare the code with what you see on the screen.\n";

cout&lt;&lt; "n1: " &lt;&lt; n1 &lt;&lt; "\n";

cout&lt;&lt; "n2: " &lt;&lt; n2 &lt;&lt; "\n";

cout&lt;&lt; "n3: " &lt;&lt; n3 &lt;&lt; "\n";

cout&lt;&lt; "n4: " &lt;&lt; n4 &lt;&lt; "\n";

cout&lt;&lt; "n5: " &lt;&lt; n5 &lt;&lt; "\n";

cout&lt;&lt; "n6: " &lt;&lt; n6 &lt;&lt; "\n";

cout&lt;&lt; "n7: " &lt;&lt; n7 &lt;&lt; "\n";

double n17;

n17 = n1 + n7;

cout&lt;&lt; "n1 + n7 = " &lt;&lt; n17 &lt;&lt; "\n";

double n26;

n26 = n2 + n6;

cout&lt;&lt; "n2 + n6 = " &lt;&lt; n26 &lt;&lt; "\n";

double n35;

n35 = n3 + n5;

cout&lt;&lt; "n3 + n5 = " &lt;&lt; n35 &lt;&lt; "\n";

double n45;

n45 = n4 + n5;

cout&lt;&lt; "n4 + n5 = " &lt;&lt; n45 &lt;&lt; "\n";

double n33;

n33 = n3 + n3;

cout&lt;&lt; "n3 + n3 = " &lt;&lt; n33 &lt;&lt; "\n";

string bye;

cin&gt;&gt; bye;

return 0;

}

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/BeatKeaper
πŸ“…︎ Jul 01 2012
🚨︎ report
Are C programs and libraries expected to look like the standard library?

Hello. I learned C some time ago and wondered if looking into the standard library could give me more insight into how the language works and maybe learn new idioms. Right when I begun studying I tried doing that with glibc, but I left with my head spinning. I tried doing it again now, and also looked up musl-libc, but I still can't understand almost anything of what's going on. In musl, the pow function has more than 300 lines. I can't even imagine what else I could do for an exponentiation function besides a simple for loop. I also looked up some other libraries and programs, like X11, but many of them just look like walls of files and headers, with walls of preprocessor directives inside. I don't think I'd ever be able to come up with something as complex.

πŸ‘︎ 14
πŸ’¬︎
πŸ‘€︎ u/CapFolling_
πŸ“…︎ Jan 13 2022
🚨︎ report
How are macros expanded in Clang?

I have a macro identifier token, how do I get it's value?

Source: Blah.c

#define Blah 0

Clang: This code is in Preprocessor::HandleBlahDirective

Token MacroName;
LexUnexpandedToken(MacroName);
if (MacroName.is(tok::identifier))
  // What do I do here, how do I get "0"?
  // getLiteralData() == NULL
  // IdentifierInfo-&gt;getName() == tok::identifier
  // IdentifierInfo-&gt;getName().data() == "Blah"
  // IdentifierInfo-&gt;getNameStart() == "Blah"
  // getLocation().printToString() == "Blah.c:1"
}

Already asked on IRC and cfe-dev, been completely ignored in both places.

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/SuddenlysHitler
πŸ“…︎ Dec 02 2021
🚨︎ report
I created a quiz where you need to write all C# keywords. Hope you enjoy it :) sporcle.com/games/promant…
πŸ‘︎ 193
πŸ’¬︎
πŸ‘€︎ u/Promant
πŸ“…︎ Aug 12 2021
🚨︎ report
Best C Marco Preprocessor Tutorial? (Book or Website)

It seems to me that the Macro Preprocessor can be so useful for avoiding writing duplicate code, yet to me, optimal and correct usage are not very obvious.

There are lots of tech books written about very small niches, like "Understanding and Using Pointers" (which I personally found a lot less useful than ASM Step by Step).

Yet I haven't found any books about "Mastering C Macros" or something like that.

Of course we can learn everything on our own via trial and error and digging through the infinite codebase that is Github... But I sure find a structured "tutorial"/"exercises" style introduction speeds me up a lot, especially for tools that I haven't used much.

Are there a few chapters of some of the more popular C books that focus on preprocessor macros?
Of course there are websites that I've seen, and if that's the way to go, it would be immensely helpful to have some recommendations for the best ones. The best thing about book versions is that you can read reviews to make sure the author really knows what they're talking about...

πŸ‘︎ 16
πŸ’¬︎
πŸ‘€︎ u/J_A_P_H
πŸ“…︎ Jan 15 2022
🚨︎ report
You will be able to modify color values directly inside CSS with the 'color()' function, no preprocessor needed. Now draft at W3C for CSS4 cloudfour.com/thinks/buil…
πŸ‘︎ 26
πŸ’¬︎
πŸ‘€︎ u/theKovah
πŸ“…︎ Aug 12 2016
🚨︎ report
Bungie C++ Guidelines & Razors

Source: https://www.bungie.net/en/News/Article/50666


There's a lot of teamwork and ingenuity that goes into making a game like Destiny. We have talented people across all disciplines working together to make the best game that we can. However, achieving the level of coordination needed to make Destiny isn’t easy.

It's like giving a bunch of people paintbrushes but only one canvas to share between them and expecting a high-quality portrait at the end. In order to make something that isn't pure chaos, some ground rules need to be agreed upon. Like deciding on the color palette, what sized brushes to use in what situations, or what the heck you’re trying to paint in the first place. Getting that alignment amongst a team is incredibly important.

One of the ways that we achieve that alignment over in engineering land is through coding guidelines: rules that our engineers follow to help keep the codebase maintainable. Today, I'm going to share how we decide what guidelines we should have, and how they help address the challenges we face in a large studio.

The focus of this post will be on the game development side of things, using the C++ programming language, but even if you don't know C++ or aren't an engineer, I think you'll still find it interesting.

##What's a Coding Guideline?

A coding guideline is a rule that our engineers follow while they're writing code. They're commonly used to mandate a particular format style, to ensure proper usage of a system, and to prevent common issues from occurring. A well-written guideline is clearly actionable in its wording, along the lines of "Do X" or "Don't do Y" and explains the rationale for its inclusion as a guideline. To demonstrate, here’s a couple examples from our C++ guidelines:

> Don't use the static keyword directly

  •  The "static" keyword performs a bunch of different jobs in C++, including      declaring incredibly dangerous static function-local variables.            You should use the more specific wrapper keywords in      cseries_declarations.h, such as static_global, static_local, etc. This      allows us to audit dangerous static function-locals efficiently.   * 
    

> > > > > > > > > > >

> Braces On Their Own Lines

  •  Braces are always placed on a line by themselves.            There is an exception permitted for single-line inline function      definitions.   * 
    

> > > &gt

... keep reading on reddit ➑

πŸ‘︎ 954
πŸ’¬︎
πŸ‘€︎ u/DTG_Bot
πŸ“…︎ Aug 31 2021
🚨︎ report
Equivalent to C WORDSIZE et al preprocessor definitions?

Hi! I'm interested in making a D wrapper for GNU Lightning for a part of a hobby language implementation. The problem is I'm immediately hitting a wall in terms of how to translate lightning.h (available in GNU Lightning releases from here to D. It contains myriad preprocessor directives, most of which can be trivially translated to D, but some of which seems somewhat trickier. Take the below code (lines 35-58 in lightning.h):

#ifndef __WORDSIZE
#  if defined(WORDSIZE)				/* ppc darwin */
#    define __WORDSIZE		WORDSIZE
#  elif defined(__SIZEOF_POINTER__)		/* ppc aix */
#    define __WORDSIZE		(__SIZEOF_POINTER__ &lt;&lt; 3)
#  elif defined(_ILP32)				/* hppa hp-ux */
#    define __WORDSIZE		32
#  elif defined(_LP64)				/* ia64 hp-ux (with cc +DD64) */
#    define __WORDSIZE		64
#  elif defined(_MIPS_SZPTR)			/* mips irix */
#    if _MIPS_SZPTR == 32
#      define __WORDSIZE	32
#    else
#      define __WORDSIZE	64
#    endif
#  else						/* From FreeBSD 9.1 stdint.h */
#    if defined(UINTPTR_MAX) &amp;&amp; defined(UINT64_MAX) &amp;&amp; \
	(UINTPTR_MAX == UINT64_MAX)
#      define __WORDSIZE	64
#    else
#      define __WORDSIZE	32
#    endif
#  endif
#endif

I guess the problem might just be that I don't really... get what this code is doing. I know that the builtin D version specifications can probably help me, but would my naive approach of just making a long list of all the builtin versions that would specify 64-bit or 32-bit and assigning __WORDSIZE appropriately really get the job done? Although the above code is still just an elif chain, it seems somewhat more complex than the approach I was contemplating.

πŸ‘︎ 2
πŸ’¬︎
πŸ‘€︎ u/humbleSolipsist
πŸ“…︎ Jan 04 2022
🚨︎ report
Do you understand C language code that contain #ifdef directives? Could you answer a few questions?

Hello, We are evaluating the comprehension of source code that contains #ifdefs directives.

We are currently looking for IT professionals, students, professors and researchers who have a basic knowledge of the C language and #ifdefs directives to evaluate the comprehension of source code by answering a survey. If you are a professional in this field, your opinion is important and valuable to us.

The average response time is 15 minutes.

The survey and more information are available at this link: https://djansantos.com.br/experimento/

We would appreciate it if you could share the link with anybody that has basic experience with C language and #ifdef.

If you have any questions, feel free to get in touch.

Ph.D. candidate: Djan Santos (UFBA-Brazil) - djan.info@gmail.com

advisor: ClΓ‘udio Sant'Anna (UFBA-Brazil) - co-advisor: MΓ‘rcio Ribeiro (UFAL-Brazil)

Thank you!

πŸ‘︎ 11
πŸ’¬︎
πŸ‘€︎ u/DjanSantos
πŸ“…︎ Sep 28 2021
🚨︎ report
Any older programmers or game editors out there? Trying to decompile/compile two files from an old game -- one works the other doesn't.

tldr; I'm trying to decompile/compile two old game files & one works, but the other requires some includes that we can't seem to get around.

THE WHOLE STORY:

Not even sure where to start, but I'm not a c++ programmer, and I'm in over my head. A group of people still play this old game - FPS Baseball Pro 98, (a 16 bit game, that we use a W98 VM to run. The league data is stored into two files: .asn & .pyr. We have an old command line utility (dattotxt.exe) that can decompile the files: .asn -> .tsn .pyr -> .tyr

The .tsn file looks like this: [File ASN96] #include "assn.h" #include "citynum.h"

[OpenBlock ASN01]
1                        // id
ASSNTYPE_CONT
STAGE_SDRAFT_START
2                        // num seasons
... (thousands of lines)

These are ascii readable files that can be edited with notepad. We can recompile the .tsn -> .asn, because we have two of the includes: assn.h & citynum.h. To do this we run cpp.exe filename.tsn

The results are:

C:\SIERRA\DATFILES&gt;cpp 28jbl001.tsn
Borland C++ Preprocessor Version 3.1 Copyright (c) 1992 Borland International
28jbl001.tsn:

		Available memory 4211764

C:\SIERRA\DATFILES&gt;

After that, we take the resulting file filename.i and run another command to re-create the .asn file

Txttodat -y2 -tASN 08abl001.i

We'd like to do the same with the .pyr/tyr file. However we run into a bunch of includes. Most of which we have. But we get down to this:

C:\SIERRA\2&gt;cpp 28nrb001.tyr
Borland C++ Preprocessor Version 3.1 Copyright (c) 1992 Borland International
28nrb001.tyr:
Error 28nrb001.tyr 3: Unable to open include file 'player.h'
*** 1 errors in Compile ***

		Available memory 4221420

... (add a bunch of includes) ...

Once we add iostream.h, we get this oddity.

C:\SIERRA\2&gt;cpp 28nrb001.tyr
Borland C++ Preprocessor Version 3.1 Copyright (c) 1992 Borland International
28nrb001.tyr:
Fatal iostream.h 19: Error directive: Must use C++ for the type iostream.
*** 1 errors in Compile ***

		Available memory 4207284

The only way around it, has been to change the filetype from .tyr to .cpp. That then results in this:

C:\SIERRA\2&gt;cpp 28nrb001.cpp
Borland C++ Preprocessor Version 3.1 Copyright (c) 1992 Borland International
28nrb001.cpp:
Error iostream.h 26: Unable to open include file '_defs.h'
Error iostream.h 30: Unable to open include file 'mem.h'
... keep reading on reddit ➑

πŸ‘︎ 3
πŸ’¬︎
πŸ‘€︎ u/MarquisEXB
πŸ“…︎ Dec 11 2021
🚨︎ report
C programming, I want to help you learn !

Context

Learning from books is fairly conventional, but in 2021, you rarely see people (not in this subreddit) recommending learning from books.

I just finished the ANSI C programming language book, and it was as awesome as it was challenging. So, I highly recommend you do try it !

Why ?

I was okay at C before beginning this book, I've written a dozen of C programs, was comfortable-ish with pointers/structs etc. and used preprocessor directives/header files ... What I want to say; I thought I didn't need to learn C, and instead focus on making, until I encountered this: The 0x10 Best Questions for Would-be Embedded Programmers.

So ?

The book has many exercises, and although I didn't go through all of them, I can say that I enjoyed and got headaches over a handful of them.

The problem I encountered with some exercises is that they don't have "solutions" attached, or enough details (for a beginner like me), which added to the friction of going through them. I understand that not everyone is as fortunate as I am to have enough time and drive to tackle such problems, that's why I maintained a GitHub repo containing all the "solutions" I produced since day one (23 days ago).

Link: https://github.com/Rad-hi/ANSI_C

Final thoughts

I hope this helps someone get better at what they do, or explore something new to them. I am really hoping this doesn't come up as self-promotion, I really just want to give back to the community.

Have a good day, and happy learning.

Edit* : Improved readability with formatting.

πŸ‘︎ 202
πŸ’¬︎
πŸ‘€︎ u/radixties
πŸ“…︎ Sep 26 2021
🚨︎ report
How can I overcome this error?

I'm trying to create this "how to Build a Basic Android Game in Just 7 Minutes (Unity)" game by Android Authority on Youtube and I've done up to 4:18 min

However, I'm getting this error "Assets\Script\PlayerControlls.cs(5,15): error CS1040: Preprocessor directives must appear as the first non-whitespace character on a line" in unity!?

πŸ‘︎ 2
πŸ’¬︎
πŸ“…︎ Nov 22 2021
🚨︎ report
Q1 keymap with Caps Lock and Fn layer indicators v1.0.3

NOTE: This custom firmware is, at this point in time, only for the original Q1 models (without knob) which have the atmega32u4 MCU. I am waiting for Keychron and/or QMK to add official support for the new Q1 with knob which has the STM32L432 MCU before I update this firmware.

I've updated my Q1 keymap originally posted here. This keymap builds on the awesome keymap by Grayson Carr (/u/gtg465x2) but adds a few options:

  • All custom keycodes defined in VIA user keycodes range (USER00, USER01, etc)

  • macOS shortcuts for Mission Control (F3) and Launchpad (F4)

  • RGB lighting turns off when system suspends/sleeps

  • Caps Lock indicator with several options:

    • #define CAPS_LOCK_INDICATOR_COLOR [color] in config.h to set the backlight color used for the indicator when Caps Lock is enabled (default: red)
    • Fn+Z will toggle lighting the TAB key when Caps Lock is enabled. This is useful with non backlit keycaps/legends. (default: off)
    • Fn+X will toggle lighting all the alpha keys when Caps Lock is enabled. (default: off)
  • Dynamic Fn Layer RGB indicator. When the Fn key is held down, this will highlight any Fn layer key definitions made in this firmware or in VIA with several options:

    • #define FN_LAYER_COLOR [color] in config.h to set a static color for defined keys (default: orange)
    • Fn+C will toggle turning off RGB for Fn layer keys with no definition (default: RGB off for non-defined Fn layer keys)
    • Fn+V will toggle lighting the defined Fn layer keys with the static color set with FN_LAYER_COLOR (default: static color off)
  • All custom keycodes in this firmware can be moved to different keys in VIA by using the ANY key with the following keycodes:

    • USER00 (default: F3) macOS Mission Control
    • USER01 (default: F4) macOS Launchpad
    • USER02 (default: Fn+Z) Caps Lock light Tab toggle
    • USER03 (default: Fn+X) Caps Lock light alphas toggle
    • USER04 (default: Fn+C) Fn layer non-defined keys RGB toggle
    • USER05 (default: Fn+V) Fn layer defined keys static color toggle

RGB must be toggled on for all indicators to function. If you do not want an RGB mode active but still want the indicators, toggle RGB on and turn the brightness all the way off. The indicators will remain at full brightness.

Pl

... keep reading on reddit ➑

πŸ‘︎ 33
πŸ’¬︎
πŸ‘€︎ u/k1ds3ns4t10n
πŸ“…︎ Oct 08 2021
🚨︎ report
SERIOUS: This subreddit needs to understand what a "dad joke" really means.

I don't want to step on anybody's toes here, but the amount of non-dad jokes here in this subreddit really annoys me. First of all, dad jokes CAN be NSFW, it clearly says so in the sub rules. Secondly, it doesn't automatically make it a dad joke if it's from a conversation between you and your child. Most importantly, the jokes that your CHILDREN tell YOU are not dad jokes. The point of a dad joke is that it's so cheesy only a dad who's trying to be funny would make such a joke. That's it. They are stupid plays on words, lame puns and so on. There has to be a clever pun or wordplay for it to be considered a dad joke.

Again, to all the fellow dads, I apologise if I'm sounding too harsh. But I just needed to get it off my chest.

πŸ‘︎ 17k
πŸ’¬︎
πŸ‘€︎ u/anywhereiroa
πŸ“…︎ Jan 15 2022
🚨︎ report
Blind Girl Here. Give Me Your Best Blind Jokes!

Do your worst!

πŸ‘︎ 5k
πŸ’¬︎
πŸ‘€︎ u/Leckzsluthor
πŸ“…︎ Jan 02 2022
🚨︎ report
French fries weren’t cooked in France.

They were cooked in Greece.

πŸ‘︎ 9k
πŸ’¬︎
πŸ“…︎ Jan 20 2022
🚨︎ report
This subreddit is 10 years old now.

I'm surprised it hasn't decade.

πŸ‘︎ 14k
πŸ’¬︎
πŸ‘€︎ u/frexyincdude
πŸ“…︎ Jan 14 2022
🚨︎ report
You've been hit by
πŸ‘︎ 6k
πŸ’¬︎
πŸ‘€︎ u/mordrathe
πŸ“…︎ Jan 20 2022
🚨︎ report
Having a little trouble understanding the different kinds of declarations and definitions that are written outside the main function

Hey guys, I'm jumping into C and as the title states, I was hoping for a little help with my understanding of what exists outside (above or below, I've read that it doesn't matter which) the main function.

So there are various C pre-processor directives, that preform different tasks, the most important of which is the #include directive. This directive literally includes header.h files into the main.c source code, as if the code inside the header.h file was included directly in the main.c file. I know the #include directive goes deeper, like which directories it searches for the header files in, but I'll look more into that later.

I've heard header files can contain any C code, but it's best practice to only have them contain simple statements, like variable and function declarations.

But here's what's confusing me, and what I'm currently still researching - what are the declarations above main? The function declarations without a body, and the variable declarations? Where are the definitions of these function signatures? And why declare these variables outside the main scope, especially when you can #define symbolic constants? This confusion extends to when header.h files only contain similar function and variable declarations.

I'll post answers if I find them, thanks guys!

πŸ‘︎ 9
πŸ’¬︎
πŸ‘€︎ u/WishfulLearning
πŸ“…︎ Oct 22 2021
🚨︎ report

Please note that this site uses cookies to personalise content and adverts, to provide social media features, and to analyse web traffic. Click here for more information.