TITLE: True Or not: Compact iff every continuous function is bounded
QUESTION [11 upvotes]: Let $X$ be a topological space. My question is:
If $f:X\to \mathbb{R}$ is bounded for all such continuous $f$, then is $X$ compact. Is is really?
If $X$ is the subset of $\mathbb{R}^d$, then it is clear, beacause with Heine-Borel we get what we want (closed and bounded (with the help of the norm)), but is it true in general? I really hope there exists a non-compact space with the property above.

REPLY [12 votes]: To complement Martini's answer, one may add that if the space $X$ is $metrizable$, then the answer is "yes".
Indeed, assume that $X$ is metrizable and not compact. Then one can find a sequence $(x_n)_{n\in\mathbb N}\subset X$ with $x_n\neq x_m$ if $n\neq m$, such that the set $C=\{ x_n;\; n\in\mathbb N\}$ is discrete in the topology induced by $X$. Then the function $f_0=C\to\mathbb R$ defined by $f_0(x_n)=n$ is continuous and unbounded. Moreover, $C$ is closed in $X$, so by Tietze's extension theorem $f_0$ can be extended to a continuous (and unbounded!) function $f:X\to\mathbb R$.
Apologies: I did not notice that Davide Giraudo gave the same answer in a comment above.