Leaderboard - أكاديمية حسوب

[ANSYS FLUENT] How do I read/write files in parallel using UDF?

Hey all, I'm trying to create a udf that reads a file containing x,y,z coordinates and then returning the value of the cell nearest to it. I managed to create the code, but I have trouble parallelizing it. At first, I had trouble because ansys repeats my udf 4 times (which is equal to the number of solver processes I input), so I decided to just use my udf on compute node zero by using if(I_AM_NODE_ZERO_P). However, I began to realize that this will fail because the other compute nodes will not be processed, and thus the I will not get the cell values at those compute nodes. My question now is, how do I parallelize reading/writing csv files using UDF? I consulted the ansys documentation on parallelizing udf, but I do not know how to start. Here is my code:
#include  #include  #include  #include  #include  static ND_Search *domain_table = NULL; DEFINE_ON_DEMAND(find_cells) { #if !RP_HOST if(I_AM_NODE_ZERO_P){ cell_t c; Thread *t; CX_Cell_Id *cx_cell; real cCentroid; real cVolume; real P[3]; real P_Cell[3]; FILE *fp; char line[1024]; int rayID, side, prevID, nextID, surfID; double x,y,z; fp = fopen("rays_csv_new.csv","r"); if(fp == NULL){ printf("Trouble reading file\nAborting.."); fclose(fp); abort(); } domain_table = CX_Start_ND_Point_Search(domain_table,TRUE,-1); Message("Starting Cell Search..."); while(fgets(line,1024,fp)){ sscanf(line,"%d,%lg,%lg,%lg,%d,%d,%d,%d",&rayID,&x,&y,&z,&side,&prevID,&nextID,&surfID); P[0] = x; P[1] = y; P[2] = z; cx_cell = CX_Find_Cell_With_Point(domain_table,P,0.0); if(cx_cell){ c = RP_CELL(cx_cell); t = RP_THREAD(cx_cell); cCentroid = C_CENTROID(P_Cell,c,t); cVolume = C_VOLUME(c,t); Message("%g \t %g \t %g \t %g\n",P[0],P[1],P[2],cVolume); }else{ Message("Could not find cell at [%g,%g,%g]\n",P[0],P[1],P[2]); } } domain_table = CX_End_ND_Point_Search(domain_table); fclose(fp); } #endif } 
I tested my code the following dataset:
x y z 0.227898,1.0,-0.448053 4,-0.106937,1.0,0.379007 7,-0.350153,1.0,0.031367 9,0.293532,1.0,0.357582 11,-0.403077,1.0,-0.409584 13,0.476352,1.0,-0.0787738 15,-0.400827,1.0,-0.0563139 18,0.189004,1.0,0.217153 
Since I was only processing compute node 0, the cells that are within compute node 0 will be found, but those that are outside it won't. As a result, the output looks like this:
Could not find cell at [0.227898,1,-0.448053] Could not find cell at [-0.106937,1,0.379007] Could not find cell at [-0.350153,1,0.0313674] 0.293532 1 0.357582 1.82506e-08 Could not find cell at [-0.403077,1,-0.409584] Could not find cell at [0.476352,1,-0.0787738] Could not find cell at [-0.400827,1,-0.0563139] 0.189004 1 0.217153 1.95857e-08 
submitted by rephical to CFD [link] [comments]

Setting VMIN to 0 blocks ANSI escape sequence writing to stdin, and setting VMIN to 1 blocks my whole program. Please help me understand

I am trying to make a function that returns the terminal size by utilizing ANSI escape sequences. It works in 2 steps: - \033[9999;9999H forces the cursor to the rightmost bottom-most position - \033[6n fills ESC[rows;colsR into stdin You also have to use termios.h to set ~(ICANON | ECHO) to prevent input blocking when you try to read stdin, and to prevent the terminal immediately echoing stdin to stdout and thus removing the useful thing from stdin.
I will not go into parsing the sequence in stdin, because the culprit as I see it is in the detail of setting VMIN to 1. In my actual code, I am running VMIN = 0 and read()-ing STDIN (1) in an infinite loop. Setting VMIN to 0 just completely breaks my program and it freezes.
Here is a minimal example showcasing how changing VMIN affects the success of running the ANSI escape sequence "DSR" to generate a response to stdin containing the cursor position:
```C

include

include

include

include

define SIZE 100

int main ( void) { int ch = 0; int i = 0; struct termios original, changed;
// change terminal settings tcgetattr( STDIN_FILENO, &original); changed = original; changed.c_lflag &= ~( ICANON | ECHO); changed.c_cc[VMIN] = 1; changed.c_cc[VTIME] = 0; tcsetattr( STDIN_FILENO, TCSANOW, &changed); printf ( "\033[9999;9999H"); // cursor should move as far as it can printf ( "\033[6n"); // ask for cursor position printf ( "\033[2J"); //clear screen printf ( "\033[1;1H"); // move to upper left corner while ( ( ch = getchar ()) != 'R') {// R terminates the response if ( EOF == ch) break; if ( isprint ( ch)) // print out only normal chars to not mess up display printf("stdin[%d]\t==\t%d\t==\t%c\n", i, ch, ch); else printf("stdin[%d]\t==\t%d\t==\t\n", i, ch); i++; } // restore terminal settings tcsetattr( STDIN_FILENO, TCSANOW, &original); return 0; 
} `` To try this out, just chech what happens whenVMINis1, and when it's0`.
My problems in short: - Setting VMIN to 1 breaks my program - When VMIN is 0, the escape sequence response to stdin doesn't work
Currently, the only solution I see is to pass the termios struct to the function and change VMIN for 1 picosecond just to run the 2 lines that do the ANSI code and read from stdin. But this looks hacky, and doesn't answer the question WHY this happens and how it works. If I can't find a good compromise, I may use the ioctl() solution.
If anyone has any idea about why this happens, I would be very obliged. My goal is to understand this behavior and adapt my code in the best possible way.
Thank you very much for your time.
submitted by iloveclang to C_Programming [link] [comments]

QMK Breaking Changes - 2022 August 27 Changelog

QMK Breaking Changes - 2022 August 27 Changelog

Notable Features

Add Raspberry Pi RP2040 support (#14877, #17514, #17516, #17519, #17612, #17512, #17557, #17817, #17839, #18100)

QMK finally picked up support for RP2040-based boards, such as the Raspberry Pi Pico, the Sparkfun Pro Micro RP2040, and the Adafruit KB2040. One of QMK's newest collaborators, @KarlK90, effectively did /micdrop with RP2040, with a massive set of changes to both QMK and the repository QMK uses for the base platform support, ChibiOS[-Contrib]. There has been a flurry of development this breaking changes cycle related to RP2040 from a large number of contributors -- so much so that almost all standard QMK hardware subsystems are supported.
Check the [RP2040 platform development page](platformdev_rp2040.md) for all supported peripherals and other hardware implementation details.

Allow qmk flash to use prebuilt firmware binaries (#16584)

A long-requested capability of the QMK CLI has been the ability to flash binaries directly, without needing to build a firmware. QMK provides prebuilt develop-based default firmwares on our CI page -- normally people would need QMK Toolbox to flash them. This new functionality written by @Erovia allows qmk flash to be provided the prebuilt file instead, simplifying the workflow for people who haven't got Toolbox available.

Changes Requiring User Action

Default layers dropped from 32 to 16 (#15286)

QMK allows for controlling the maximum number of layers it supports through LAYER_STATE_(8|16|32)BIT. Each definition allows for the same number of maximum layers -- LAYER_STATE_8BIT => 8 layers. There is also a corresponding firmware size decrease that goes along with smaller numbers -- given the vast majority of users don't use more than 16 layers the default has been swapped to 16. AVR users who were not previously specifying their max layer count may see some space freed up as a result.

RESET => QK_BOOT (#17940)

Following the last breaking changes cycle, QMK has been migrating usages of RESET to QK_BOOT due to naming collisions with our upstream board support packages. #17940 converts user keymaps across to use the new keycode name. RESET should also move to QK_BOOT.

Updated Keyboard Codebases

The following keyboards have had their source moved within QMK:
Old Keyboard Name New Keyboard Name
gentleman65 jkeys_design/gentleman65
handwired/hillside/0_1 handwired/hillside/48
idobao/id80/v1/ansi idobao/id80/v2/ansi
idobao/id80/v1/iso idobao/id80/v2/iso

Data-driven USB IDs Refactoring (#18152)

QMK has decided to deprecate the specification of USB IDs inside config.h in favour of info.json, eventually leaving data-driven as the only method to specify USB information.
A significant number of keyboards have already been changed on master in a like-for-like fashion, and #18152 performs the same transformations for keyboards already on develop.
Previously in config.h:
#define VENDOR_ID 0x1234 #define PRODUCT_ID 0x5678 #define DEVICE_VER 0x0001 #define MANUFACTURER Me #define PRODUCT MyKeyboard 
Replaced by info.json:
{ "keyboard_name": "MyKeyboard", "manufacturer": "Me", "usb": { "vid": "0x1234", "pid": "0x5678", "device_version": "0.0.1" }, // ... layouts, etc. ... } 

Deprecation Schedule

Notable core changes

Board converters (#17514, #17603, #17711, #17827, #17593, #17652, #17595)

Historically QMK had a CONVERT_TO_PROTON_C directive for rules.mk to allow people to replace an AVR-based Pro Micro with a QMK Proton C. Global parts shortages have prompted people to create their own pin-compatible boards -- QMK has made this conversion generic and now allows for drop-in replacements for a lot more boards. see the [Converters Feature](feature_converters.md) documentation for the full list of supported replacement boards -- in this breaking changes cycle we've gone from 1 to 7.

Add cli command to import keyboard|keymap|kbfirmware (#16668)

To help with importing keyboards and keymaps from other sources, @zvecr added #16668 which adds a new set of commands to the CLI to automatically import keyboards (qmk import-keyboard -h), keymaps (qmk import-keymap -h), and kbfirmware definitions (qmk import-kbfirmware -h) into QMK.
The now-EOL kbfirmware allowed people who aren't set up with QMK the ability to create keyboard firmwares without requiring a full installation of QMK. Unfortunately, it targets a 7-year-old version of QMK -- adding frustration for users who want the newest features, as well as for QMK maintainers who have to spend time explaining why QMK can't just accept a drive-by code drop from kbfirmware. With any luck, this new command helps both camps!

Generic wear-leveling for EEPROM emulation (#16996, #17376, #18102)

QMK has had the ability to write to internal MCU flash in order to emulate EEPROM for some time now, but it was only limited to a small number of MCUs. The base HAL used by QMK for a large number of ARM devices provides a "proper" embedded MCU flash driver, so @tzarc decoupled the wear-leveling algorithm from the old flash writing code, improved it, wrote some tests, and enabled its use for a much larger number of other devices... including RP2040's XIP flash, and external SPI NOR Flash.
See the [EEPROM Driver](eeprom_driver.md) documentation for more information.

Pointing Device Improvements (#16371, #17111, #17176, #17482, #17776, #17613)

Ever since Pointing Device Driver support and Split Pointing Device support were added by @drashna and @daskygit, there has been increased interest in the development of the pointing device subsystem and its associated code.
Both the PMW33xx and the Cirque Pinnacle implementations have seen a lot of improvement to their code, as has the mouse code in general. Features like circulaedge scrolling for the Cirque, and Kinetic movement for any sensor with "lift detection" (#17482). Additionally, for those that make fast motions with their pointing devices, support for much larger mouse movement reports has been added (#16371).
Other related changes:

Full changelist :id=full-changelist

Core:
CLI:
Submodule updates:
Keyboards:
Keyboard fixes:
Others:
Bugs:
submitted by tzarc to olkb [link] [comments]

Managed C v2.3.0 - Complete rewrite and full ANSI-C compatibility!

https://github.com/Frityet/ManagedC/releases/tag/v2.3.0
Managed C is a reference counter for C, allowing you to easily create and use referenced counted pointers.
Usage:
```c

include

include "managed.h"

//We get a pointer to the value that we can free //It is a double pointer because we have an array //of pointers in main void free_int_ref(int *ref) { //This function will be called for each item in the array printf("Value: %d\n", *ref);
//mc_free is used for deallocating "managed" types. mc_free(ref); 
}
int main() { int **alloc_list = mc_array(int *, 5, &free_int_ref);
alloc_list[0] = mc_alloc(int, NULL); *alloc_list[0] = 11; alloc_list[1] = mc_alloc(int, NULL); *alloc_list[1] = 10; alloc_list[2] = mc_alloc(int, NULL); *alloc_list[2] = 9; alloc_list[3] = mc_alloc(int, NULL); *alloc_list[3] = 8; alloc_list[4] = mc_alloc(int, NULL); *alloc_list[4] = 7; mc_free(alloc_list); 
} ```
Changelog: - Completely rewrote the library to use ANSI C89, and compiling in that mode, however with extensions you get type checking, and additional features such as mc_auto. - Threading support! Mutexes are fully implemented on POSIX and Windows - Safety improvements across the board - Dynamically grow-able list (that doesn't break existing references!) - Consistent naming - Clang extensions! mc_defer for defer functionality - Proper testing - Many more changes I can't remember!
See readme for usage!
(Also, if you want to run the tests make sure you are on the master branch!)
submitted by Frityet5 to C_Programming [link] [comments]

Making simply a function, what should I use for arguments?

Recently, I've been trying to write libraries in ansi-c, but a question came to my mind. I have to take almost 5-6 arguments for each function, what if instead it opens a struct and uses it to use each function?
For example:
#include  struct fs { int a; int b; int c; int d; }; int four_sum(struct fs sum) { return sum.a+sum.b+sum.c+sum.d; } int main() { struct fs sum1 = {1, 2 ,3, 4}; struct fs sum2 = {2, 4, 6, 8}; printf("%d\n", four_sum(sum1)); printf("%d\n", four_sum(sum2)); return 0; } 
Seems good to me but I'm just a newbie what do you think about that? Do you want to use a library written like this?
submitted by SteryNomo to C_Programming [link] [comments]

C program Cheat Sheet by genta (4 pages) #programming #c

C program Cheat Sheet by genta (4 pages) #programming #c submitted by Cheatography to Cheatography [link] [comments]

QMK Breaking Changes - 2022 May 28 Changelog

QMK Breaking Changes - 2022 May 28 Changelog

Notable Features

Caps Word (#16588)

This is a new feature that allows for capslock-like functionality that turns itself off at the end of the word.
For instance, if you wish to type "QMK" without holding shift the entire time, you can either tap both left and right shift, or double-tap shift, to turn on Caps Word -- then type qmk (lowercase) without holding shift. Once you hit any key other than a--z, 0--9, -, _, delete, or backspace, this will go back to normal typing!
There are other activation mechanisms as well as configurable options like timeout and the like -- see the Caps Word documentation for more information.

Quantum Painter (#10174)

QMK has had support for small OLED displays for some time now, but hasn't really gained too much ability to draw to panels other than the SSD1306 or SH1106 panels.
Quantum Painter is a new drawing subsystem available to suitable ARM and RISC-V boards that is capable of drawing to large panel RGB LCDs and RGB OLEDs. It also allows for a lot more flexibility with a larger set of drawing APIs -- lines, rectangles, circles, ellipses, text, images, and even animations.
The QMK CLI has new commands added to be able to generate images and fonts for Quantum Painter to digest -- it's even capable of converting animated gifs for display on screen.
See the Quantum Painter documentation for more information on how to set up the displays as well as how to convert images and fonts.
Quantum Painter is not supported on AVR due to complexity and size constraints. Boards based on AVR such as ProMicro or Elite-C builds will not be able to leverage Quantum Painter.

Encoder Mapping (#13286)

One of the long-standing complaints with Encoders is that there has been no easy way to configure them in user keymaps. #13286 added support for Encoder Mapping, which allows users to define encoder functionality in a similar way to their normal keymap.
This is not yet supported by QMK Configurator. It is also unlikely to ever be supported by VIA.

Changes Requiring User Action

RESET => QK_BOOT (#17037)

QMK is always in the process of picking up support for new hardware platforms. One of the side-effects for future integrations has shown that QMK's usage of RESET as a keycode is causing naming collisions. As a result, #17037 changed usages of RESET to the new keycode QK_BOOT in the majority of default-like keymaps. At this stage the old keycode is still usable but will likely be removed in the next breaking changes cycle. Users with keymaps containing RESET should also move to QK_BOOT.

Sendstring keycode overhaul (#16941)

Some keycodes used with SEND_STRING and its relatives have been deprecated and may have their old keycode usages removed at a later date. The list of deprecated keycodes should be consulted to determine if you're using one of the older names (the first identifier after #define) -- you should swap to the newer variant (the second identifier on the same line).

Pillow Installation (#17133)

The merge of Quantum Painter added some new dependencies in the QMK CLI, most notably Pillow, which requires some installation in order for the CLI to function. If you've got an existing installation, you'll need to run some commands in order to get things working:
On Windows, if using QMK MSYS or msys2, you'll need to run the following command:
pacman --needed --noconfirm --disable-download-timeout -S mingw-w64-x86_64-python-pillow python3 -m pip install --upgrade qmk
On macOS:
brew update brew upgrade qmk/qmk/qmk
On Linux or WSL:
python3 -m pip install --user --upgrade qmk

Updated Keyboard Codebases

The following keyboards have had their source moved within QMK:
Old Keyboard Name New Keyboard Name
absinthe keyhive/absinthe
amj40 amjkeyboard/amj40
amj60 amjkeyboard/amj60
amj96 amjkeyboard/amj96
amjpad amjkeyboard/amjpad
at101_bh viktus/at101_bh
ergosaurus keyhive/ergosaurus
gmmk/pro/ansi gmmk/pro/rev1/ansi
gmmk/pro/iso gmmk/pro/rev1/iso
honeycomb keyhive/honeycomb
lattice60 keyhive/lattice60
melody96 ymdk/melody96
mt40 mt/mt40
mt64rgb mt/mt64rgb
mt84 mt/mt84
mt980 mt/mt980
navi10 keyhive/navi10
omnikey_bh viktus/omnikey_bh
opus keyhive/opus
smallice keyhive/smallice
southpole keyhive/southpole
uno keyhive/uno
ut472 keyhive/ut472
wheatfield/blocked65 mt/blocked65
wheatfield/split75 mt/split75
z150_bh viktus/z150_bh

Full changelist

Core:
CLI:
Submodule updates:
Keyboards:
Keyboard fixes:
Others:
Bugs:
submitted by tzarc to olkb [link] [comments]

This showcases all the syntatic features of the C programming language

allc.c:
/* allc.c - This showcases all the syntatic * features of the C programming language. (C11) */ /* preprocessing directive */ #if 1 /* if directive */ # /* null directive; has no effect */ #line 12 /* line directive */ #define NULL (void *)0 /* define directive */ #undef NULL /* undef directive */ #ifdef D /* ifdef directive */ #endif #ifndef D /* ifndef directive */ #endif #pragma deadbeef /* pragma directive */ #elif /* elif directive */ #else /* else directive */ #if defined 0 #endif #include  /* include directive */ #error "error" /* error directive */ #endif /* endif directive */ /* variadic macro */ #define VAMACRO(...) __VA_ARGS__ /* static assertion */ _Static_assert(sizeof(char) == 1, "test"); /* stringizing operator */ #define stringize(x) #x /* token pasting operator */ #define concat(a, b) a##b /* external storage types and example of variadic function */ extern int printf(const char *, ...); /* array declarator */ afuncd(a[const 10]); /* function pointer */ int (*ifunc)(void); /* array of function pointer */ int (*afunc[10])(void); /* enumerations */ enum enum_t { EA, EB, EC, ED }; enum { VA, VB, VC, VD } enum_variation; /* structures */ struct struct_t { char a, b, c; /* bitfields */ int b1:4, b2:4; /* anonymous union */ union { int e, f; }; /* flexible array member */ int arr[]; }; struct { char a, b, c; } struct_variation; /* unions */ union union_t { int a, b; /* anonymous struct */ struct { int c, d; }; }; union {char a;}; union_variation; /* alias for a data type */ typedef struct struct_t struct_t; typedef union union_t union_t; typedef enum enum_t enum_t; /* forward declaration */ int trigraphsavailable(); /* inline function. trigraphs */ inline int trigraphsavailable() // returns 0 or 1; language standard C99 or later { // are trigraphs available??/ return 0; return 1; } /* _Noreturn */ _Noreturn void noret(void){ } /* empty return */ void ret(void){ return; } /* incomplete VLA types */ void icomplete(int n, int a[*]); /* function */ int main(argc, argv) /* pre-ANSI C declarations */ int argc; char **argv; { /* predefined macros */ __DATE__; __FILE__; __LINE__; __STDC__; /* 1 indicates conforming implementation */ __STDC_HOSTED__; __STDC_VERSION__; /* yymmL */ __TIME__; /* type specifiers */ char a; int b; float c; double d; void *p; float _Complex Co; _Bool Bo; long lo; short sho; signed si; unsigned un; float _Imaginary; { /* comma operator */ int a, b, c; /* pointer to arrays*/ int (*p)[10]; /* casting */ int d = (int)1.0; int e = (int)&d; } /* array declaration */ int ar[10]; /* string literal */ "Hello " "C"; /* string literal suffix */ u8"Hello " "C"; u"Hello " "C"; U"Hello " "C"; L"Hello " "C"; /* character literal*/ a = 'a'; /* escape sequence */ "\n" /* newline */ "\t" /* horizontal tab */ "\\" /* backslash */ "\f" /* form feed */ "\r" /* carriage return */ "\?" "\01" /* octal character escape */ "\x1" /* hexadecimal character escape */ "\v"; /* vertical tab */ /* stringize operator */ stringize(Hello C); /* "Hello C" */ /* Token pasting operator */ concat(a, r); /* ar */ /* demonic array */ 1 [ar] = 1; /* array designated initializer */ int ar2[10] = {[0] = 1, [1] = 2, [2] = 3}; /* struct designated initializer */ struct_t s = {.a = 1, .b = 2, .c = 3}; /* arrow operator */ (&s)->a; /* dot operator */ (struct_t){0}.a = 1; (union_t){0}.a = 1; /* compound literals */ (int[]){1, 2, 3, 4}; /* compound literals with designated initializer*/ (int[]){[0] = 1, [1] = 2, [2] = 3, 4}; (struct {int a, b, c}){.a=1, .b=2, .c=3}; /* other fancy designated initializer */ (struct {int a, b, c}[1]){[0] = {.a = 1, .b = 2, .c = 3}}; /* assignment operators */ a = 0; a *= 1; a /= 1; a += 1; a -= 1; a <<= 1; a >>= 1; a &= 1; a ^= 1; a |= 1; a %= 1; /* address and indirection operators */ &a; *ar; /* arithmetic operators */ 1 + 1; /* ADD */ 1 - 1; /* SUB */ 1 / 2; /* DIV */ 1 * 1; /* MUL */ 1 % 1; /* MOD */ /* logical operators */ 1 && 1; /* AND */ 1 || 0; /* OR */ !1; /* NOT */ /* + and - */ { int a = -10; int b = +a; /* b = 10 */ int c = 10; int d = -c; /* d = -10 */ } /* increment and decrement operators */ a++; a--; /* post fix */ ++a; --a; /* pre fix */ /* bitwise operators */ 1 << 2; /* left shift */ 1 >> 2; /* right shift */ 1 | 1; /* OR */ 1 & 1; /* AND */ 1 ^ 1; /* XOR */ ~1; /* 1st complement */ /* relational operators */ 1 > 0; /* 1 is greater than 0 */ 1 < 0; /* 1 is less than 0 */ 1 == 0; /* 1 is equal to 0 */ 1 != 0; /* 1 is not equal to 0 */ 1 >= 0; /* 1 is greater than or equal to 0 */ 1 <= 0; /* 1 is less than or equal to 0 */ /* conditions */ if (1 > 0) ; else ; /* ternary operators */ (1 > 0) ? 1 : 0; /* if 1 > 0, return 1, else 0 */ /* label and goto */ goto l1; l1: /* loops */ do while(0); while (0) ; for (; 0;) continue; ; /* block scoping */ {} /* switch statement */ switch (1){ case 0: case 1: default: break; } /* digraphs */ ar<:0:> = 1; /* ar[0] */ <% %> /* { } */ %:define BEEF /* #define BEEF */ /* demonic digraphs */ 0<:ar:> = 1; /* storage-class specifier */ static st; register re; auto au; extern ex; _Thread_local static Thr; /* _Generic */ _Generic((10), int: 1, char: 'A', default: "test"); /* type qualifiers */ const cons; int *restrict res; volatile vo; _Atomic At; /* sizeof, _Alignof and _Alignas operators */ sizeof(int); sizeof 1+1; _Alignof(int); _Alignas(4) char calign[4]; /* integer constants */ 1; /* decimal */ 1ul; 1UL; /* unsigned long suffix */ 1ull; 1ULL; /* unsigned long long suffix */ 01 ; /* octal */ 0x01; /* hexadecimal */ /* floating point constants */ /* decimal floating point constant */ 1.0e+1f; 1e1f; /* hexadecimal floating point constant */ 0x01.00p+1f; 0x1p+1f; /* function call */ trigraphsavailable(); /* return keyword */ return 0; } 
Pretty sure "demonic arrays" was stated in the C standard. ~I just made it up~
Forgive me if I forgotten something. I wonder how it would like with other language like C++.
submitted by harieamjari to C_Programming [link] [comments]

How to access a bidimensional array by pointer

Hi everyone! I have trying to access a 2-dimensional array by pointer in ANSI C language like this:
```

include "bsp.h"

include "stdio.h"

typedef struct baz { uint8_t * bar; uint8_t foo; } baz_t;
uint8_t arrayTest[2u][3u] = { { 0x55u, 0xAAu, 0xA5u }, { 0x5Au, 0xFFu, 0x88u } };
void main() {
baz_t testAccess = { .bar = &arrayTest[0][0], .foo = 0x00u };
baz_t * ptestAccess = &testAccess;
/* Here is my problem, I get a compiler error */ printf("\nTest Value = %d", ptestAccess->bar[1u][1u]); } ```
Could someone help me on this issue? I don't know why I can't get the value 0xFFu on printf statement when I pass this reference ptestAccess->bar[1u][1u]
Note: When I use a translator to unidimensional array (using a macro for example), this feature works! XD
See below the workarround that I did:
``` /* Translator definition after the includes */

define ACCESS_TRANSLATOR(row, col) ptestAccess->bar[(row * 3u) + col]

/* some code * . * . * . */
/* New workable printf call */ printf("\nTest Value = %d", ACCESS_TRANSLATOR(1u, 1u)); ```

..::Edit_01::..

Thanks everyone, I made this solution with your help and I would like your opnion about it: https://onlinegdb.com/3kIi2DNan

..::Edit_02::..

And now, with your help, I made this another solution (I my opnion, this one is more applicable to my project): https://onlinegdb.com/23WKhRkau

Are there something more to improve?

Note: I removed the snippet of the solution from this comment in order to keep this explanation as "short" as possible. But, you are able to find the link to the solution on the GDB online as I put above.
submitted by JuSakura42 to embedded [link] [comments]

Simple CLI Colorizing in Go

I wrote a blog post on a little function I made for simply handling colorizing terminal output in Go: https://h0wl.xyz/simple-cli-colorizing-in-go/
It's not a hard thing to do, but I wanted to share with anyone that might be trying to print various variable types to the console. I haven't covered every possible type in Go and their specific conversion to a string, but it's easy enough to add a new case for a different input type.
Here's the function and expected variables:
var ( // Colors and font options via ANSI escape codes Reset = "\033[0m" Black = "\033[30m" Red = "\033[31m" Green = "\033[32m" Yellow = "\033[33m" Blue = "\033[34m" Magenta = "\033[35m" Cyan = "\033[36m" Gray = "\033[37m" White = "\033[97m" Bold = "\033[1m" Italic = "\033[3m" Underline = "\033[4m" Invert = "\033[7m" ) func Color(input interface{}, color ...string) string { var s string c := "" for i := range color { c = c + color[i] } switch v := input.(type) { case int: s = c + strconv.Itoa(v) + Reset case bool: s = c + strconv.FormatBool(v) + Reset case []string: s = c + strings.Join(v, ", ") + Reset case string: s = c + v + Reset default: fmt.Printf("Unsupported type provided to Color func - %T\n", v) } return s } 
The way I have it structured allows for easily applying multiple font options to an input.
For example, fmt.Println(Color(variableName, Blue, Bold)) will print a variable in Blue and Bold.
submitted by zachhh to golang [link] [comments]

Problem compailing basic C Code

Hello Folks!
I know it's a pretty basic question, for this class of coding.
I started recently to learn programming in my High Degree Studies. One of the subjects, was learn to program on C and C++ for Arduino boards, and give him functions and orders. Okay...

I started recently to learn the basic C or ANSI C. With Code Blocks IDE, with GCC Compiler.

One of my problems, was the very basic Hello World "Or Hello Planets" with C, and this type of IDE and compiler.

// Hello World in C

#include

int main()
{
printf (" Hello Dude! ")

return 0;
}

And give a strange debugging error, while compailing xD. The error was the line #include Is one of the header or libraries, the problem is, the compiler or IDE, not recognising this line or library, a bit strange.

This is the Screenshot:
https://images2.imgbox.com/72/55/byvlWB5X_o.jpg

Thanks!
submitted by ErizerX41 to learnprogramming [link] [comments]

Escape character issue when trying to color terminal text in C++

I'm trying to write a simple function for my program that prints a string to the terminal in a given color. I wanted it to be cross-platform, so I used ANSI escape codes. Here's what I have:
#ifndef COLORS_H #define COLORS_H #include  #include  #include  using namespace std; // escape strings to be added to input strings to make colored output text const string red = "%c[1;31m"; const string green = "%c[1;32m"; const string yellow = "%c[1;33m"; const string blue = "%c[1;34m"; const string revert = "%c[0m"; void printC(string input, string color) { string escapestring = ""; if (color == "red") { escapestring = red; } else if (color == "green") { escapestring = green; } else if (color == "yellow") { escapestring = yellow; } else if (color == "blue") { escapestring = blue; } string outstring = escapestring + input + revert; cout << outstring << revert << endl; } // method to simplify the process of printing a given string in a given color #endif 
I'm getting an error in VSCode though. The string variable in the declaration of the printC function is highlighted and the error that appears when hovering over it is "format '%c' expects argument of type int but argument 2 has type const char*"
I'm not sure what this is supposed to mean, and the only references to this error I can find online have to do with printf, which I'm not using.
Any ideas?
submitted by mrmayge to learnprogramming [link] [comments]

noob question ANSI C

How do I compile ANSI C? I'm learning from C programming language second edition when I run a.out in Linux ofcourse it doesn't work you have to do ./a.out. what OS would I have to use to learn this version of C exactly like this book instructs?
Example
#include  main() { printf("desu"); } 
I understand it's outdated and little practical use but I think it's cool and I'm only doing it for fun. Im a complete noob so some of the thermology I'm using may be incorrect hope you understand what I am trying to convey.
submitted by zg05qkqa8cpwBuHBNfQq to C_Programming [link] [comments]

[Request]Please help compiling latest futurerestore for iOS14

[Request]Please help compiling latest futurerestore for iOS14
I tried to compile futurerestore from marijuanARM/futurerestore 's fork.
I have compiled most of external libs :
https://preview.redd.it/8tcpwa25z4061.png?width=1258&format=png&auto=webp&s=9ca3b114ce7669de5b51f08e62865b91f2139b54

https://preview.redd.it/houpq009z4061.png?width=1112&format=png&auto=webp&s=191feca746113b617cf5a9fac237dd72acf56f94
But when I start compiling tihmstaliboffsetfinder64, it gives me an error:

https://preview.redd.it/7adfgx1qz4061.png?width=1610&format=png&auto=webp&s=e85a582646d5cbe5e534bf74f569161b48efb4e4
When compiling liboffsetfinder64 's dependecy tihmstalibinsn, it gives errors.
Macos Catalina 10.15.7
Last login: Thu Nov 19 12:25:57 on ttys001
[email protected] ~ % cd Desktop/BuildFuturerestore
[email protected] BuildFuturerestore % cd libinsn
[email protected] libinsn % ./autogen.sh
checking build system type... x86_64-apple-darwin19.6.0
checking host system type... x86_64-apple-darwin19.6.0
checking target system type... x86_64-apple-darwin19.6.0
checking how to print strings... printf
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for a sed that does not truncate output... /usbin/sed
checking for grep that handles long lines and -e... /usbin/grep
checking for egrep... /usbin/grep -E
checking for fgrep... /usbin/grep -F
checking for ld used by gcc... /Library/DevelopeCommandLineTools/usbin/ld
checking if the linker (/Library/DevelopeCommandLineTools/usbin/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /usbin/nm -B
checking the name lister (/usbin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 196608
checking how to convert x86_64-apple-darwin19.6.0 file names to x86_64-apple-darwin19.6.0 format... func_convert_file_noop
checking how to convert x86_64-apple-darwin19.6.0 file names to toolchain format... func_convert_file_noop
checking for /Library/DevelopeCommandLineTools/usbin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver u/FILE support... no
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking command to parse /usbin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... yes
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking for gcc option to produce PIC... -fno-common -DPIC
checking if gcc PIC flag -fno-common -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/Library/DevelopeCommandLineTools/usbin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin19.6.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for a BSD-compatible install... /usbin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking whether make sets $(MAKE)... yes
checking whether make supports the include directive... yes (GNU style)
checking whether make supports nested variables... yes
checking dependency style of gcc... gcc3
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... /Library/DevelopeCommandLineTools/usbin/ld
checking if the linker (/Library/DevelopeCommandLineTools/usbin/ld) is GNU ld... no
checking whether the g++ linker (/Library/DevelopeCommandLineTools/usbin/ld) supports shared libraries... yes
checking for g++ option to produce PIC... -fno-common -DPIC
checking if g++ PIC flag -fno-common -DPIC works... yes
checking if g++ static flag -static works... no
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (/Library/DevelopeCommandLineTools/usbin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin19.6.0 dyld
checking how to hardcode library paths into programs... immediate
checking dependency style of g++... gcc3
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking whether we need platform-specific build settings... checking for pkg-config... /uslocal/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for libgeneral >= 32... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking for stdint.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for unistd.h... (cached) yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating include/Makefile
config.status: creating libinsn/Makefile
config.status: creating libinsn.pc
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing libtool commands
config.status: executing depfiles commands

Configuration for libinsn-32:
-------------------------------------------

install prefix ..........: /uslocal

compiler ................: gcc

Now type 'make' to build libinsn-32,
and then 'make install' for installation.

[email protected] libinsn % make
(CDPATH="${ZSH_VERSION+.}:" && cd . && /bin/sh /Users/kinken/Desktop/BuildFuturerestore/libinsn/missing autoheader)
rm -f stamp-h1
touch config.h.in
cd . && /bin/sh ./config.status config.h
config.status: creating config.h
config.status: config.h is unchanged
/Library/DevelopeCommandLineTools/usbin/make all-recursive
Making all in libinsn
/bin/sh ../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I. -I.. -I../include -I../include/libinsn -I/uslocal/include -g -O2 -stdlib=libc++ -std=c++14 -O3 -fPIC -D EXPECTIONNAME=INSNexception -MT libinsn_la-insn_decode.lo -MD -MP -MF .deps/libinsn_la-insn_decode.Tpo -c -o libinsn_la-insn_decode.lo \test -f 'insn_decode.cpp' || echo './'`insn_decode.cpp`
libtool: compile: g++ -DHAVE_CONFIG_H -I. -I.. -I../include -I../include/libinsn -I/uslocal/include -g -O2 -stdlib=libc++ -std=c++14 -O3 -fPIC -D EXPECTIONNAME=INSNexception -MT libinsn_la-insn_decode.lo -MD -MP -MF .deps/libinsn_la-insn_decode.Tpo -c insn_decode.cpp -fno-common -DPIC -o .libs/libinsn_la-insn_decode.o
In file included from insn_decode.cpp:12:
../include/libinsn/INSNexception.hpp:19:78: error: no matching constructor for initialization of 'tihmstar::exception'
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^ ~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/exception.hpp:15:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 3 were provided
class exception : public std::exception{
^
/uslocal/include/libgeneral/exception.hpp:22:9: note: candidate constructor not viable: requires at least 5 arguments, but 3 were provided
exception(const char *commit_count_str, const char *commit_sha_str, int line, const char *filename, const char *err ...);
^
insn_decode.cpp:121:5: error: no matching constructor for initialization of 'tihmstar::INSNexception'
assure(len != -1); //reserved value
^~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:80:52: note: expanded from macro 'assure'
...assure(cond) do{ if ((cond) == 0) throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, "assure failed"); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:124:5: error: no matching constructor for initialization of 'tihmstar::INSNexception'
assure(immediate && (imms & levels) != levels); //reserved value
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:80:52: note: expanded from macro 'assure'
...assure(cond) do{ if ((cond) == 0) throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, "assure failed"); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:142:2: warning: TODO incomplete function implementation! [-W#warnings]
#warning TODO incomplete function implementation!
^
insn_decode.cpp:185:2: warning: TODO redo this! currently only recognises STR (immediate) [-W#warnings]
#warning TODO redo this! currently only recognises STR (immediate)
^
insn_decode.cpp:554:17: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("unexpected subtype");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:560:17: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("unexpected subtype");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:547:44: warning: result of comparison of constant 73031290881 with expression of type 'unsigned int' is always false
[-Wtautological-constant-out-of-range-compare]
if (BIT_RANGE(_opcode, 21, 30) == 0x1101011001 /* register_extended */) {
~~~~~~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~
insn_decode.cpp:606:17: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("unexpected classtype for insn");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:634:13: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("can't get imm value of unknown instruction");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:670:17: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("can't get imm value of ldr that has non immediate subtype");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:674:17: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("can't get imm value of ldr that has non immediate subtype");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:684:17: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("can't get imm value of ldr that has non immediate subtype");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:701:17: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("ldrb must be st_immediate for imm to be defined!");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:704:2: warning: TODO rewrite this! currently only unsigned offset supported [-W#warnings]
#warning TODO rewrite this! currently only unsigned offset supported
^
insn_decode.cpp:722:13: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("failed to get imm value");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:731:13: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("can't get rd of unknown instruction");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:749:13: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("failed to get rd");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:757:13: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("can't get rn of unknown instruction");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:781:13: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("failed to get rn");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:789:13: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("can't get rt of unknown instruction");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:807:13: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("failed to get rt");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
insn_decode.cpp:818:13: error: no matching constructor for initialization of 'tihmstar::INSNexception'
reterror("failed to get rt2");
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/uslocal/include/libgeneral/macros.h:84:43: note: expanded from macro 'reterror'
# define reterror(errstr ...) do{ throw tihmstar::EXPECTIONNAME(VERSION_COMMIT_COUNT, VERSION_COMMIT_SHA, __LINE__, __FILE__, errstr); } while(0)
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/libinsn/INSNexception.hpp:19:9: note: candidate constructor not viable: no known conversion from 'const char [3]' to 'int' for 1st argument
INSNexception(int code, const char *filename, const char *err ...) : tihmstar::exception(code,filename,err){}
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided
class INSNexception : public tihmstar::exception{
^
../include/libinsn/INSNexception.hpp:17:11: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 5 were provided
fatal error: too many errors emitted, stopping now [-ferror-limit=]
4 warnings and 20 errors generated.
make[2]: *** [libinsn_la-insn_decode.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
[email protected] libinsn %
submitted by Yuenkinken to jailbreak [link] [comments]

Build Errors makepkg package-query

For a school project I need to install yaourt. So before I can start installing yaourt I need to install package-query. I want to install package-query from source but whenever I try to build using makepkg I get a couple of warnings and an error. I have not been able to find out why the warnings/errors are being generated so was wondering if anyone is able to help me out.
This is the message I get when I try to build the makepkg:
[[email protected] package-query]$ makepkg ==> Making package: package-query 1.11-1 (Wed Jun 2 15:23:08 2021) ==> Checking runtime dependencies... ==> Checking buildtime dependencies... ==> Retrieving sources... -> Found package-query-1.11.tar.gz ==> Validating source files with md5sums... package-query-1.11.tar.gz ... Passed ==> Extracting sources... -> Extracting package-query-1.11.tar.gz with bsdtar ==> Removing existing $pkgdi directory... ==> Starting build()... checking for a BSD-compatible install... /usbin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usbin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking whether gcc understands -c and -o together... yes checking whether make supports the include directive... yes (GNU style) checking dependency style of gcc... gcc3 checking build system type... armv7l-unknown-linux-gnueabihf checking host system type... armv7l-unknown-linux-gnueabihf checking how to print strings... printf checking for a sed that does not truncate output... /usbin/sed checking for grep that handles long lines and -e... /usbin/grep checking for egrep... /usbin/grep -E checking for fgrep... /usbin/grep -F checking for ld used by gcc... /usbin/ld checking if the linker (/usbin/ld) is GNU ld... yes checking for BSD- or MS-compatible name lister (nm)... /usbin/nm -B checking the name lister (/usbin/nm -B) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 1572864 checking how to convert armv7l-unknown-linux-gnueabihf file names to armv7l-unknown-linux-gnueabihf format... func_convert_file_noop checking how to convert armv7l-unknown-linux-gnueabihf file names to toolchain format... func_convert_file_noop checking for /usbin/ld option to reload object files... -r checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for dlltool... no checking how to associate runtime and link libraries... printf %s\n checking for ar... ar checking for archiver @FILE support... @ checking for strip... strip checking for ranlib... ranlib checking command to parse /usbin/nm -B output from gcc object... ok checking for sysroot... no checking for a working dd... /usbin/dd checking how to truncate binary pipes... /usbin/dd bs=4096 count=1 checking for mt... no checking if : is a manifest tool... no checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for dlfcn.h... yes checking for objdir... .libs checking if gcc supports -fno-rtti -fno-exceptions... no checking for gcc option to produce PIC... -fPIC -DPIC checking if gcc PIC flag -fPIC -DPIC works... yes checking if gcc static flag -static works... yes checking if gcc supports -c -o file.o... yes checking if gcc supports -c -o file.o... (cached) yes checking whether the gcc linker (/usbin/ld) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes checking ctype.h usability... yes checking ctype.h presence... yes checking for ctype.h... yes checking getopt.h usability... yes checking getopt.h presence... yes checking for getopt.h... yes checking glob.h usability... yes checking glob.h presence... yes checking for glob.h... yes checking libintl.h usability... yes checking libintl.h presence... yes checking for libintl.h... yes checking limits.h usability... yes checking limits.h presence... yes checking for limits.h... yes checking locale.h usability... yes checking locale.h presence... yes checking for locale.h... yes checking regex.h usability... yes checking regex.h presence... yes checking for regex.h... yes checking signal.h usability... yes checking signal.h presence... yes checking for signal.h... yes checking sys/ioctl.h usability... yes checking sys/ioctl.h presence... yes checking for sys/ioctl.h... yes checking for sys/stat.h... (cached) yes checking sys/utsname.h usability... yes checking sys/utsname.h presence... yes checking for sys/utsname.h... yes checking for alpm_version in -lalpm... yes checking for pkg-config... /usbin/pkg-config checking pkg-config is at least version 0.9.0... yes checking for alpm... yes checking for yajl_free in -lyajl... yes checking for gawk... (cached) gawk checking for curl-config... /usbin/curl-config checking for the version of libcurl... 7.77.0 checking for libcurl >= version 7.19.4... yes checking whether libcurl is usable... yes checking for curl_free... yes checking for git... git checking for .git/... no checking that generated files are newer than configure... done configure: creating ./config.status config.status: creating src/Makefile config.status: creating doc/Makefile config.status: creating Makefile config.status: creating config.h config.status: config.h is unchanged config.status: executing depfiles commands config.status: executing libtool commands package-query: Build information: source code location : . prefix : /usr sysconfdir : /etc conf file : /etc/pacman.conf localstatedir : /var database dir : /valib/pacman/ compiler : gcc compiler flags : -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16 -O2 -pipe -fstack-protector-strong -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-clash-protection package-query version : 1.11 using git version : no git ver : Variable information: root working directory : / aur base url : https://aur.archlinux.org make all-recursive make[1]: Entering directory '/home/alarm/tempAUpackage-query/src/package-query-1.11' Making all in src make[2]: Entering directory '/home/alarm/tempAUpackage-query/src/package-query-1.11/src' gcc -DLOCALEDIR=\"/usshare/locale\" -DCONFFILE=\"/etc/pacman.conf\" -DROOTDIR=\"/\" -DDBPATH=\"/valib/pacman/\" -DAUR_BASE_URL=\"https://aur.archlinux.org\" -DHAVE_CONFIG_H -I. -I.. -D_GNU_SOURCE -march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16 -O2 -pipe -fstack-protector-strong -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-clash-protection -MT alpm-query.o -MD -MP -MF .deps/alpm-query.Tpo -c -o alpm-query.o alpm-query.c alpm-query.c: In function 'init_alpm': alpm-query.c:74:2: warning: implicit declaration of function 'alpm_option_set_arch'; did you mean 'alpm_option_set_dlcb'? [-Wimplicit-function-declaration] 74 | alpm_option_set_arch (handle, config.arch); | ^~~~~~~~~~~~~~~~~~~~ | alpm_option_set_dlcb alpm-query.c: In function 'parse_config_server': alpm-query.c:96:21: warning: implicit declaration of function 'alpm_option_get_arch'; did you mean 'alpm_option_get_dlcb'? [-Wimplicit-function-declaration] 96 | const char *arch = alpm_option_get_arch (config.handle); | ^~~~~~~~~~~~~~~~~~~~ | alpm_option_get_dlcb alpm-query.c:96:21: warning: initialization of 'const char *' from 'int' makes pointer from integer without a cast [-Wint-conversion] alpm-query.c: In function 'search_pkg': alpm-query.c:397:22: error: too few arguments to function 'alpm_db_search' 397 | alpm_list_t *pkgs = alpm_db_search (db, targets); | ^~~~~~~~~~~~~~ In file included from util.h:23, from alpm-query.c:28: /usinclude/alpm.h:1413:5: note: declared here 1413 | int alpm_db_search(alpm_db_t *db, const alpm_list_t *needles, | ^~~~~~~~~~~~~~ make[2]: *** [Makefile:429: alpm-query.o] Error 1 make[2]: Leaving directory '/home/alarm/tempAUpackage-query/src/package-query-1.11/src' make[1]: *** [Makefile:409: all-recursive] Error 1 make[1]: Leaving directory '/home/alarm/tempAUpackage-query/src/package-query-1.11' make: *** [Makefile:341: all] Error 2 ==> ERROR: A failure occurred in build(). Aborting... 
submitted by Henqk to archlinux [link] [comments]

Simple terminal based game without flicker.

Simple terminal game without flicker

Soooo,
I made a simple game that runs in the terminal and uses ANSI codes to avoid clearing the screen wich would cause flicker. The game is very based on this video by Sebastian Lague. I also made a simple snake game (source: github.com). I will also make a video on the game on my channel Eclips-Coding. Code: ```c // GCC source.c resource.o -o SS.exe -Werror -Wall -W -lpthread

include // Header for multithreading

include // Header for working with windows

include // Header for string manipulation

include // Header for general use

include // Header for input & output

include // Header for time

define RED "\e[31m" // RED = ANSI code for red text

define GREEN "\e[32m" // GREEN = ANSI code for green text

define BLUE "\e[34m" // BLUE = ANSI code for blue text

define NC "\e[0m" // NC = ANSI code for white text

define SPEED 500 // SPEED = 500

typedef struct // Custom variable { int x; // Value x int y; // Value y }PIX; // Name = PIX
PIX b; // Variable for the bullet PIX p; // Variable for the player PIX e; // Variable for the enemy int i; // Variable for the input int m = 0; // Variable for the multiplyer int s = -1; // Variable for the score pthread_t inputThread; // Variable for the input thread
int random(int min, int max); // Function to get a random number void *In(); // Function to get input from the player void SpawnShip(); // Function to spawn a new enemy ship void Start(); // Function to start the game void Test(); // Function to test if we have collisions void Draw(); // Function to draw the game to the terminal void Move(); // Functoin to move everything in the game void End(); // Function to clean up before exiting
void Start() // Function to start the game { printf("\e[?25l"); // Hide the terminal cursor pthread_create(&inputThread, NULL, In, NULL); // Make a thread for the input function
b.x = -1; // Set the bullet x out of the screen b.y = -1; // Set the bullet y out of the screen p.x = 0; // Set the player x in the left of the screen p.y = 4; // Set the player y in the middle of the screen SpawnShip(); // Spawn an enemy ship 
}
void End() // Function to clean up before exiting { printf("\e[12B"); // Move the cursor down 12 lines printf("\e[?25h"); // Unhide the cursor
exit(0); // Exit the program normaly 
}
int random(int min, int max) // Function to get a random number { srand(time(0)); // Set the seed of the generator to the current time
return (rand() % (max - min + 1)) + min; // Generate a random number and fit it between {min} & {max} 
}
void *In() // Function to get input from the player { char c; // Variable to hold the pressed character
while (1) // Loop for ever { c = getch(); // Get the character the user pressed and store it in c if (c == 'w') // If the user pressed W { i = 1; // Set the input to 1 } else if (c == 's') // If the user pressed S { i = 2; // Set the input to 2 } else if (c == ' ') // If the user pressed SPACE { i = 3; // Set the input to 3 } else if (c == 'q') // If the user pressed q { i = 4; // Set the input to 4 } } 
}
void Move() // Function to move everything in the game { b.x++; // Add 1 to the bullet x
if (i == 1) // If input equals 1 { p.y--; // Remove 1 from the players y i = 0; // Set the input to 0 } else if (i == 2) // If input equals 2 { p.y++; // Add 1 to the players y i = 0; // Set the input to 0 } else if (i == 3) // If input equals 3 { b.x = p.x; // Set bullet x equal to player x b.x += 2; // Add 2 to bullet x b.y = p.y; // Set bullet y equal to player y i = 0; // Set input to 0 } else if (i == 4) // If input equals 4 { End(); // End the game } 
}
void SpawnShip() // Function to spawn a new enemy ship { s++; // Add 1 to the score m = s; // Set the multiplier to the score e.x = 15; // Set the enemy x to 15 e.y = random(1, 6); // Set the enemy y to a number between 1 and 6
b.x = -1; // Set the bullet x of screen b.y = -1; // Set the bullet y of screen if (s >= 8) // If the score is larger then or equal to 8 { m = 8; // Set the multiplier to 9 } 
}
void Test() // Function to test if we have a collision { if ( ( e.x == b.x || // If the enemy x equals the bullet x e.x == b.x +1 // Or if the enemy x equals the bullet x +1 ) && // And ( e.y == b.y -1 || // If the enemy y equals the bullet y -1 e.y == b.y || // Or if the enemy y equals the bullet y e.y == b.y +1 // Or if the enemy y equals the bullet y +1 ) ) { SpawnShip(); // Spawn a new ship }
if (e.x == 0 || // If the enemy x matches 0 (e.x == p.x + 1 && e.y == p.y) // Or if the enemy x matches the player x +1 & the enemy y matches the player y ) { End(); // End the game } e.x--; // Add 1 to the enemy x 
}
void Draw() // Function to draw the game to the terminal { char buff[1000]; // Buffer to hold the game to draw
sprintf(buff, "(W & S to move, SPACE to shoot, Q to quit)\nScore: %d\n", s); // Add a prompt to the buffer for (int y = 0; y < 10; y++) // Loop 10 times and store the count in y { for (int x = 0; x < 18; x++) // Loop 18 times and store the count in x { if (x == 0 || x == 17 || y == 0 || y == 9) // If x equals 0 or x equals 17 or y equals 0 or y equals 9 { strcat(buff, NC "[]" NC); // Add a white box to the buffer } else if (x == b.x + 1 && y == b.y + 1) // If x matches the bullet x +1 and y matches the bullet y +1 { strcat(buff, RED "()" NC); // Add a red ball to the buffer } else if ( // If ( x == p.x +1 && // x equals the players x +1 ( y == p.y || // And y equals the players y y == p.y +1 || // Or y equals the players y +1 y == p.y +2 // Or y equals the players y +2 ) ) || // Or ( x == p.x +2 && // X equals the players x +2 y == p.y +1 // And y equals the players y +1 ) ) { strcat(buff, GREEN "[]" NC); // Add a green box to the buffer } else if ( // If ( x == e.x + 1 && // X equals the enemys x +1 ( y == e.y || // And y equals the enemys y y == e.y +1 || // Or y equals the enemys y +1 y == e.y + 2 // Or y equals the enemys y +2 ) ) || // Or ( x == e.x && // X equals the enemys x y == e.y +1 // And y equals the enemys y +1 ) ) { strcat(buff, BLUE "[]" NC); // Add a blue box to the buffer } else // Else { strcat(buff, " "); // Add two spaces to the buffer } } strcat(buff, "\n"); // Add a new line to the buffer } strcat(buff, "\e[12A"); // Add moving up 12 lines to the buffer strcat(buff, "\e[18D"); // Add moving back 18 characters to the buffer printf(buff); // Deploy the buffer 
}
int main() // The main entry point { Start(); // Start the game
while (1) // Loop for ever { Move(); // Make any moves Draw(); // Draw the game Test(); // Test if we have collisions Sleep(SPEED - m * 50); // Wait for 500 minus the multiplier times 50 } Draw(); // Draw the game End(); // Exit the game return 0; // Exit normaly 
}
```
submitted by No_War3219 to C_Programming [link] [comments]

Why does printf behaves differently for each string assignment when I want to print colored text ?

Hi, I haven't used C in a long while and I am trying to make a small program that revolves around colouring text, similarly to the "grep" command in unix systems.
So my question is: why does the text prints red, respectively white for each string? What am I missing here?
int main() { // ANSI_RED \e[31m // ANSI_COLOR_ESCAPE \e[0m char *ch1 = "\e[31m this will print red \e[0m"; printf("%s\n",ch1); //this will print in red char ch2[100] ={'\\', 'e', '[', '3', '1', 'm' ,' ', 'n', 'o', 't', 'r', 'e', 'd', ' ', '\\', 'e', '[', '0', 'm'}; printf("%s\n",ch2); //this will print in white return 0; } 
Or how should I go about storing a string and "marking" which parts of it are supposed to be red?
Thank you in advance !
submitted by Pigeon_wizard to C_Programming [link] [comments]

how to get colored text in dwm bar

hello everyone i have been using dwm for about a year and a half now and usually ask alot of questions on threads but i cant get my head around getting colored text in my bar there is colorstatus text, color status status2d and the pango patch how can i achieve this?whenever i patch my build it conflicts with the alpha patchso i started fresh and still cant get it anything to appear in the bar , my other question is how do i apply the colors in my script and do i also need the swap save restore patch, does it have to be in ansi color code? or hex in "^YOURHEXHERE^"?to my understanding the statuscolors patch is easier but i cant get that working either , they both dont show anything on the right side of the bar even tho the bar is working on a fresh build of dwm,if anyone can point me in the right direction and explain what i can do to fix this it would be greatly apreciated....

MY BAR SCRIPT
#!/bin/sh

mail() {
mail=\`curl -su USER:PASSWD [https://mail.google.com/mail/feed/atom](https://mail.google.com/mail/feed/atom) || echo "unknown number of"\` mail=\`echo "$mail" | grep -oPm1 "(?<=)\[\^<\]+" \` echo "inb: $mail" 
}

updates() {
updates=$(checkupdates 2> /dev/null | wc -l ) echo "pcm: $updates" 
}

weather() {
weather=$(curl '[https://wttr.in/Florina,Greece?format=%t](https://wttr.in/Florina,Greece?format=%t)') echo "wea: $weather" 
}

cputemp() {
cputemp=$(sensors | grep Core | awk '{print substr($3, 2, length($3)-5)}' | tr "\\\\n" " " | sed 's/ /°C /g' | sed 's/ $//') echo "tem: $cputemp" 
}

cpufrequency() {
cpu=$(awk '{u=$2+$4; t=$2+$4+$5;if (NR==1){u1=u; t1=t;} else printf("%d%%", ($2+$4-u1) \* 100 / (t-t1) "%");}' <(grep 'cpu ' /proc/stat) <(sleep 0.5; grep 'cpu ' /proc/stat)) echo "cpu: $cpu"% 
}

ram() {
mem=$(free -h | awk '/Mem:/ { print $3 }' | cut -f1 -d 'i') echo "mem: $mem" 
}

alsa() {
volume="$(amixer get Master | tail -n1 | sed -r 's/.*\[(.*)%\].*/\1/')"
echo "vol: $volume" 
}

upspeed() {
T1=\`cat /sys/class/net/enp2s0/statistics/tx\_bytes\` sleep 1 T2=\`cat /sys/class/net/enp2s0/statistics/tx\_bytes\` TBPS=\`expr $T2 - $T1\` TKBPS=\`expr $TBPS / 1024\` printf "up: $TKBPS kb" 
}

downspeed() {
R1=\`cat /sys/class/net/enp2s0/statistics/rx\_bytes\` sleep 1 R2=\`cat /sys/class/net/enp2s0/statistics/rx\_bytes\` RBPS=\`expr $R2 - $R1\` RKBPS=\`expr $RBPS / 1024\` printf "do: $RKBPS kb" 
}

clock() {
time=$(date +"%b %d, %R") echo "$time" 
}

while true; do
xsetroot -name "$(mail) | $(updates) | $(cpufrequency) | $(ram) | $(alsa) | $(upspeed) | $(downspeed) | $(clock) |" sleep 2 
done &



submitted by Rare-Commission9452 to suckless [link] [comments]

STD::BYTE?

hello, newbie here.
I am using this walkthrough from this website:
https://www.codeproject.com/Articles/13852/BasicExcel-A-Class-to-Read-and-Write-to-Microsoft?msg=5761501#xx5761501xx

My errors are at the end.
This is my code (basically taken from the above site :))
#include #include #include #include #include #include #include #include "BasicExcel.hpp" using namespace std; using namespace YExcel; void root() { int base; int root; std::cout << "Enter base" << endl; std::cin >> base; std::cout << "Enter root" << endl; std::cin >> root; double A= std::sqrt(root); while(base*3 != A){ std::cout << "add +1 to base" << endl; base++; std::cout << "new base == " << base; //system("pause"); } std::cout << "ok worked" << endl; } int main() { BasicExcel e; //supposed to load workbook with sheet, explain contents, save to newfile: e.Load("ExcelTest1.xls"); BasicExcelWorksheet*sheet1 = e.GetWorksheet("sheet 1"); if (sheet1) { size_t maxRows = sheet1->GetTotalRows(); size_t maxCols = sheet1->GetTotalCols(); std::cout << "Dimension of " << sheet1->GetAnsiSheetName() << " (" << maxRows << ", " << maxCols << ")" << endl; printf(" "); for (size_t c = 0; c < maxCols; ++c) printf("%10d", c + 1); std::cout << endl; for (size_t r = 0; r < maxRows; ++r) { printf("%10d", r + 1); for (size_t c = 0; c < maxCols; ++c) { BasicExcelCell*cell = sheet1->Cell(r, c); switch (cell->Type()) { case BasicExcelCell::UNDEFINED: printf(" "); break; case BasicExcelCell::INT: printf("%10d", cell->GetInteger()); break; case BasicExcelCell::DOUBLE:printf("%10.6lf", cell->GetDouble()); break; case BasicExcelCell::STRING:printf("%10s", cell->GetString()); break; case BasicExcelCell::WSTRING:wprintf(L"%10s", cell->GetWString()); break; }//SWITCH FINISHES } } } Problem is the errors are: 1>c:\program files (x86)\windows kits\10\include\10.0.17763.0\shared\rpcndr.h(192): error C2872: 'byte': ambiguous symbol ---//// and: 1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\cstddef(23): note: or 'std::byte' 
I have NO idea what it's going on about

Somehow I got to a screen that says "
#define small char
typedef unsigned char byte;
typedef byte cs_byte; --//where "byte" is ambiguous?
typedef unsigned char boolean;
#ifndef _HYPER_DEFINED
#define _HYPER_DEFINED
#if (!defined(_M_IX86) || (defined(_INTEGRAL_MAX_BITS) && _INTEGRAL_MAX_BITS >= 64))
#define hyper __int64
#define MIDL_uhyper unsigned __int64

thanks
submitted by BionicleFBrE4 to cpp_questions [link] [comments]

I believe I've found the most obscure bug ever (Windows 10 CU ConHost v2 DEC Line Drawing)

TL;DR: "(0n" (in console) should display ┼ but it displays ┰ instead

In Windows 10 Creators Update, a vastly improved conhost.exe (implemented by C:\Windows\System32\ConhostV2.dll) was included.
I thought that the only changes regarding VT110/ANSI control codes were inclusion of colors. I was wrong.
According to MSDN, just about every console virtual terminal sequences known to man seems to be implemented, including a lot of very obscure ones.
One of the most obscure is the DEC Line Drawing mode. This is a way to output drawing lines by use of ASCII (lower 7-bit) letters. So, you can write:
lqwqk x x x tqnqu x x x mqvqj 
and you should get
┌─┬─┐ │ │ │ ├─┼─┤ │ │ │ └─┴─┘ 
Unfortunately, somebody made a typo (I'm guessing), and instead of typing 0x253C which is the "Box Drawings Light Vertical And Horizontal" character, they typed 0x2530 which is the "Box Drawings Down Heavy And Horizontal Light" character. So, instead of
┌─┬─┐ │ │ │ ├─┼─┤ │ │ │ └─┴─┘ 
we get
┌─┬─┐ │ │ │ ├─┰─┤ │ │ │ └─┴─┘ 
I've tested all the other DEC Line Drawing characters, and they are all correct (including the control characters). I don't have a font that has the extra obscure SCAN 1 through SCAN 9 characters, but I copied them to the clipboard and they were fiine.
You can test it on PowerShell with the following line:
Write-Host (([char]27) + '(0lqwqkedx x xedtqnquedx x xedmqvqj' + ([char]27) + '(B') 
So jenmsft, what do I win? 🙂
EDIT: I can find the actual error in the ConhostV2.dll: At position 0x43FDC-0x43FDD there's a 0x3025 instead of the correct 0x3C25 (two bytes previous to that is 0x1425 which is character ┐: Box Drawings Light Down And Left or "m" in DEC Line Drawing mode, and two bytes after that is 0xBA23, or character ⎺: Horizontal Scan Line-1 or "o" in DEC Line Drawing mode)
EDIT 2: Feedback link: https://aka.ms/Afvqwi
EDIT 3: The problem also exists on WSL Bash (reproducible by printf '\033(0lqwqk\nx x x\ntqnqu\nx x x\nmqvqj\n\033(B'). Of course, it's the same ConhostV2.dll, so I didn't expect anything different 🙂
submitted by gschizas to Windows10 [link] [comments]

Trouble Understanding K&R Bit Manipulation Example

Thank you for everyone's replies, the problem I was facing is I basically interpretted this whole thing backwards. I was thinking that p represented the least significant bit, with p+n being the most significant, when in actuality p was supposed to be the most significant bit, and p-n the least significant.
Hello,
I'm going over the K&R ANSI C book again now that I've had some formal computer science education (including a C course!), and I still don't understand what is happening here:
/* getbits: get n bits starting at position p */ unsigned getbits(unsigned x, int p, int n) { return (x >> (p+1-n)) & ~(~0 << n); } 
I just can't for the life of me understand why he's doing logical right shift by (p+1-n), and not just shifting by p.
Doing it by hand for getbits(69,1,5), using his method I get this:
69 = 1000101 base 2.
(p+1-n) = 1+1-5 = -3. To start, he says a couple paragraphs before this example that "...the number...must be non-negative", so I don't even know how to do this for one.
Using what seems to me to be the correct way of doing, i.e. shift by p, not (p+1-n), I get this by doing it by hand:
getbits(69,1,5)
69 = 1000101
1000101 >> 1 = 100010
~(~0<<5) = 11111
100010&11111 = 00010 = 2.
This is what I expect, but this is not how he wrote it and I just can't understand why. Can someone please enlighten me?
Edit: typo.
Edit2: Here's the full code if you just want to copy and paste.
#include  unsigned getbits(unsigned x, int p, int n); int main(void) { printf("%d\n", getbits(69, 1, 5)); return 0; } /* getbits: get n bits starting at position p */ unsigned getbits(unsigned x, int p, int n) { return (x >> (p+1-n)) & ~(~0 << n); } 
submitted by wutzvill to C_Programming [link] [comments]

Oddities of Dividing by Zero in C

Hello, there!
I was playing around with division by zero in C (standard used was ANSI C) using the following code:
#include
#include
int main(void)
{
printf("starting my test:\n");
printf("0.0/0.0 = %f\n", 0.0/0.0);
printf("1.0/0.0 = %f\n", 1.0/0.0);
printf("0/0 = %d\n", 0/0);
printf("1/0 = %d\n", 1/0);
printf("Done!\n");
}
I observed that 0.0/0.0=-nan, 1.0/0.0 = inf, and basic compilation using gcc -o test test.c gives no errors. However, both 0/0 and 1/0 have a division by zero warning and give a "Floating error".
Crazy question here, but can someone enlighten me on why this is? Does it have to do with 0.0 being infinitesimally different from 0 due to floating point error?
submitted by Salty_Skipper to programmingquestions [link] [comments]

الخيارات المتاحة أمامك هي إطار العمل جانغو (Django) وفلاسك (Flask) وغيرها، يمكنك تعلم لغة البرمجة بايثون لتطوير الواجهات الخلفية من خلال قراءة سلاسل المقالات عن تعلم بايثون في قسم البرمجة في أكاديمية حسوب، ثم الانتقال إلى ...

[index] [11839] [14731] [14407] [5274] [240] [8286] [620] [7087] [3027] [14724]

#

test2