{"id":31964218,"url":"https://github.com/devd4v3/assertx.h","last_synced_at":"2025-10-14T17:07:53.223Z","repository":{"id":103562364,"uuid":"171142929","full_name":"DevD4v3/assertx.h","owner":"DevD4v3","description":"Detecta sí una condición es verdadera o falsa, sí llega a ser falsa, hace que la ejecución del código termine.","archived":false,"fork":false,"pushed_at":"2019-04-24T21:12:37.000Z","size":17,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-23T02:42:49.318Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DevD4v3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-17T16:14:22.000Z","updated_at":"2021-08-19T03:51:47.000Z","dependencies_parsed_at":"2023-03-16T05:00:16.191Z","dependency_job_id":null,"html_url":"https://github.com/DevD4v3/assertx.h","commit_stats":null,"previous_names":["devd4v3/assertx.h"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DevD4v3/assertx.h","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevD4v3%2Fassertx.h","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevD4v3%2Fassertx.h/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevD4v3%2Fassertx.h/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevD4v3%2Fassertx.h/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevD4v3","download_url":"https://codeload.github.com/DevD4v3/assertx.h/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevD4v3%2Fassertx.h/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020085,"owners_count":26086805,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-14T17:07:51.384Z","updated_at":"2025-10-14T17:07:53.208Z","avatar_url":"https://github.com/DevD4v3.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# assertx.h\n\nDetiene errores lógicos o de ejecución por medio de dos macros.\n\n# Instalación\n\nAgrega el archivo `assertx.h` en la carpeta del proyecto (donde está el código fuente del programa).\n\n# Macros\n\n- `assertr(condicion, mensaje)` = Esta macro se la usa especialmente en funciones que devuelvan un valor y si la condición llega a ser falsa, detiene la ejecución de la subrutina/función.\n\n- `assertc(condicion, mensaje)` = Esta macro se la usa únicamente en bucles. Sí la condición llegara a dar un resultado de falsedad, genera otra iteración y detiene la ejecución del código que esté debajo de dicha macro.\n\n- `CHANGE_VALUE_RETURN` = Esta macro cambia el valor de retorno de la macro `àssertr` (por defecto es 0).\n\n# Aplicaciones\n\n- Un ejemplo para prevenir un error de ejecución, el típico desbordamiento de búfer.\n```C\n#include \"assertx.h\"\n\nint main(void)\n{\n\tint array[10];\n\tint n;\n\tint i;\n\twhile (1)\n\t{\n\t\tprintf(\"Cuantos elementos quieres en el array?\\n\");\n\t\tscanf(\"%d\", \u0026n);\n\t\tassertc(n != 0, \"ERROR: 0 elementos? No existe eso\")\n\t\tassertc(n \u003e= 1 \u0026\u0026 n \u003c= 10, \"ERROR: Posible buffer overflow\")\n\t\tfor (i = 0; i != n; ++i)\n\t\t\tarray[i] = i;\n\t\tbreak;\n\t}\n\tfor (i = 0; i != n; ++i)\n\t\tprintf(\"%d\\n\", array[i]);\n\tgetchar();\n\tgetchar();\n\treturn 0;\n}\n```\n- Un ejemplo para prevenir un error lógico.\n```C\n#include \u003cstdlib.h\u003e\n\n#define CHANGE_VALUE_RETURN EXIT_FAILURE\n#include \"assertx.h\"\n\nint main(void)\n{\n\tint num;\n\tprintf(\"Ingrese un numero par:\\n\");\n\tscanf(\"%d\", \u0026num);\n\tassertr(num % 2 == 0, \"ERROR: No es par.\")\n\tprintf(\"%d es par\\n\", num);\n\tgetchar();\n\tgetchar();\n\treturn EXIT_SUCCESS;\n}\n```\n\nEl mensaje de error de la macro `assertr` \u0026 `assertc` también puede ser una cadena formateada. \n- Ejemplo:\n```C\n#include \"assertx.h\"\n\nint main(void)\n{\n\tint option = 0;\n\twhile (!(option \u003e= 1 \u0026\u0026 option \u003c= 3))\n\t{\n\t\tprintf(\"Ingrese una opcion \u003c1-3\u003e:\\n\");\n\t\tscanf(\"%d\", \u0026option);\n\t\tassertc(option \u003e= 1 \u0026\u0026 option \u003c= 3, \"ERROR: El numero %d no es una opcion valida\", option)\n\t\tswitch (option)\n\t\t{\n\t\t\tcase 1:\n\t\t\t\tputs(\"Se cumplio la opcion 1\");\n\t\t\t\tbreak;\n\t\t\tcase 2:\n\t\t\t\tputs(\"Se cumplio la opcion 2\");\n\t\t\t\tbreak;\n\t\t\tcase 3:\n\t\t\t\tputs(\"Se cumplio la opcion 3\");\n\t\t}\n\t}\n\tgetchar();\n\tgetchar();\n\treturn 0;\n}\n```\nLa cadena formateada en ese ejemplo es: `\"ERROR: El numero %d no es una opcion valida\"`\n\n# Código de prueba\n\n```C\n#include \"assertx.h\"\n\nint function1(void)\n{\n\tint x;\n\tprintf(\"Ingrese un numero positivo:\\n\");\n\tscanf(\"%d\", \u0026x);\n\tassertr(x \u003e= 0, \"ERROR: Debes ingresar un numero positivo.\")\n\tprintf(\"%d es un numero positivo.\\n\", x);\n\treturn 1;\n}\n\nint main(void)\n{\n\twhile (1)\n\t{\n\t\tassertc(function1() != 0, \"\")\n\t\tbreak;\n\t}\n\tgetchar();\n\tgetchar();\n\treturn 0;\n}\n```\n\n# Resultado en pantalla\n\n[![prueba](https://i.imgur.com/XmAH6HB.png)](https://github.com/MrDave1999/assertx.h)\n\n# Créditos\n\n- [MrDave](https://github.com/MrDave1999) \n\t- Por el desarrollo de assertx.h\n- [Microsoft Corporation](https://github.com/Microsoft) \n\t- Se usó el compilador `cl.exe` para poder compilar los códigos de prueba, de ese modo se comprueba sí no hubo algún error.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevd4v3%2Fassertx.h","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevd4v3%2Fassertx.h","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevd4v3%2Fassertx.h/lists"}