Use size_t, which is better for arrays of very large sizes.

This commit is contained in:
Nicolás A. Ortega 2016-12-14 14:13:32 +01:00
parent 2a3e97f4bc
commit 5bbac132bc
No known key found for this signature in database
GPG Key ID: 614272579C2070D1
4 changed files with 4 additions and 9 deletions

View File

@ -19,7 +19,7 @@ void initList(List *restrict l) {
} }
void deInitList(List *restrict l) { void deInitList(List *restrict l) {
for(ulli i = 0; i < l->size; ++i) { for(size_t i = 0; i < l->size; ++i) {
mpz_clear(l->list[i]); mpz_clear(l->list[i]);
} }
free(l->list); free(l->list);

View File

@ -2,15 +2,13 @@
#include <gmp.h> #include <gmp.h>
#include <stdbool.h> #include <stdbool.h>
#include "types.h"
/** /**
* @brief An infinitely expanding list type. * @brief An infinitely expanding list type.
*/ */
typedef struct { typedef struct {
mpz_t *list; //!< The list of elements mpz_t *list; //!< The list of elements
ulli size; //!< How many elements are in the list size_t size; //!< How many elements are in the list
ulli end; //!< The last element of the list (in use) size_t end; //!< The last element of the list (in use)
} List; } List;
/** /**

View File

@ -5,7 +5,6 @@
#include <gmp.h> #include <gmp.h>
#include "list.h" #include "list.h"
#include "types.h"
static bool run; static bool run;
void leave(); void leave();
@ -43,7 +42,7 @@ int main(void) {
// Calculate half of `num' // Calculate half of `num'
mpz_fdiv_q_ui(halfNum, num, 2); mpz_fdiv_q_ui(halfNum, num, 2);
// Loop through found primes // Loop through found primes
for(ulli i = 0; i < primes.end; ++i) { for(size_t i = 0; i < primes.end; ++i) {
if(mpz_cmp(primes.list[i], halfNum) > 0) break; if(mpz_cmp(primes.list[i], halfNum) > 0) break;
// If `num' is divisible by a prime then go to the next number // If `num' is divisible by a prime then go to the next number
if(mpz_divisible_p(num, primes.list[i]) != 0) if(mpz_divisible_p(num, primes.list[i]) != 0)

View File

@ -1,2 +0,0 @@
#pragma once
typedef unsigned long long int ulli;