1 / 11
Nov 2010

Hey there,
i tried to solve the MUL Problem by having an array of long long and then doing normal school method on it with base 10^9 (i know there's karatsuba and FFT and so on ... but i've read that also this approach can be accepted)
I used normal C (gcc (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5)
As i need a%10^9 and a/10^9 anyway i thought i can use the lldiv-function of stdlib.h (see man div)

Now i get this compilation error:

error: 'lldiv_t' undeclared (first use in this function)

I thought this type (it's a struct) is DEFINED BY stdlib.h (which of course i included)?
On my machine, everything compiles perfectly with gcc -std=c99 (even without the -std=c99 switch - just more warning - but it compiles and runs!)
So what could be the problem? Also, the SPOJ compiler does not complain about the function lldiv but ONLY about the type lldiv_t (which just IS the return type of lldiv ...)

Something else what makes me curious is this warning i always get (although i include stdio.h)

warning: implicit declaration of function ‘fgets_unlocked’

Why do i get this warning? How can i get rid of it? I don't get the warning if i use normal fgets.

Big thanks for any help smile
Cheers

Edit: could it be that this gcc on SPOJ still compiles with -std=c89 ? - Why should this be the case? I know that lldiv_t belongs to the C99 Standard. But still: why does it compile perfectly on my machine and not here? - Maybe a problem with glibc? This is my version:

lib/libc.so.6
GNU C Library (Ubuntu EGLIBC 2.12.1-0ubuntu9) stable release version 2.12.1, by Roland McGrath et al.
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.4.5.
Compiled on a Linux 2.6.35 system on 2010-11-09.
Available extensions:
	crypt add-on version 2.1 by Michael Glad and others
	GNU Libidn by Simon Josefsson
	Native POSIX Threads Library by Ulrich Drepper et al
	BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC

Maybe this information helps? Help would really be appreciated!
As lldiv_t belongs to Stadard C99, which is -- self-explanatory -- a Standard, i think it should be compilable and accepted here, shouldn't it?
Or why should we use a 20 years old standard if there is a newer one?

Or could anyone of you tell me an alternative to lldiv (and lldiv_t)?

Please help me :mrgreen:
Thanks

  • created

    Nov '10
  • last reply

    Dec '10
  • 10

    replies

  • 614

    views

  • 2

    users

  • 2

    links

Stupid workaround:

#define __USE_ISOC99 1
#include <stdio.h>
#define __USE_ISOC99 1
#include <string.h>
#define __USE_ISOC99 1
#include <stdlib.h>

I define it several times, because some header-files UNDEFINE these again.
Got no compilation error this time (but TLE ^^) - well

But i'm still interested in this error and why it occurs!

Thanks for your reply,
well, as it compiles with gcc on my machine (version 4.4.5 as in original post) i think it also should compile here on SPOJ.
When submitting a problem i use "C (gcc 4.3.2)" as compiler.
As in the post above: I tried to solve the MUL problem
(spoj.pl/problems/MUL/)

On the site you posted, this issue is not mentioned.

Cheers

What happens when you just use the division operator? (/)

I'm just trying to peer inside the black box that you're giving me. If I had an example of the code with the issue I could compile it myself and help you more.

Okay, here is a minimal example:
I submitted the following code for the INTEST problem:

#include <stdlib.h>
int main() {
	lldiv_t foo;
	long long a=30;
	long long b=7;
	foo=lldiv(a,b);
	return 0;
}

(of course it does not solve the problem but here it's all about the compilation-error)
Submission Number=4371971
Compilation error:

/sources/tested.c: In function 'main':
/sources/tested.c:4: error: 'lldiv_t' undeclared (first use in this function)
/sources/tested.c:4: error: (Each undeclared identifier is reported only once
/sources/tested.c:4: error: for each function it appears in.)
/sources/tested.c:4: error: expected ';' before 'foo'
/sources/tested.c:7: error: 'foo' undeclared (first use in this function)

Same as before: It compiles and runs perfectly on my machine, i get compilation error here on SPOJ.
What i want:
The result of a/b AND a%b (which is (4,2))

Thank you very much for your help!

There's certainly something flaky going on.

On ideone that code compiles in C++ and C99 (which you might prefer If you code to that standard) but not C.

I need to dig deeper into how C does all that stuff.

Hm well
thanks first for you attention. I would like to have the -std=c99 option but unfortunately there is also this -pedantic-errors which makes me not use this (SPOJ-)compiler because, as already mentioned, there is also this freaky "fgets_unlocked" warning (which i don't know where it comes from), which then becomes an error frowning.

Don't knock SPOJ because of it's compiler, it just uses what GCC puts out.

Maybe you should log it in the "Bugs" section of the forum and one of the guys who codes the website could look at it. I thought they might have looked in by now, but log it there and they'll see it.

Maybe i expressed myself wrong, sorry about my english.. i didn't want to blame the SPOJ compiler. I just didn't know how to put it in different words.

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 17 10d

Want to read more? Browse other topics in C and C++ or view latest topics.