Avoiding the usage of the multicols package, what would be the proper way of having a piece of text in a page (doesn't matter if it is a new page, although it would be desired if it is halfway a two-columns page) that spans two columns and a code right there that also spans them?
MWE:
The following MWE shows what I've tried, but an error arises when uncommenting the lstlisting environment (ergo the question title).
\documentclass[journal,twoside]{IEEEtran}
\usepackage{listings}
\begin{document}
This is an empty example page.
\twocolumn[
\begin{@twocolumnfalse}
This part of the document must span the two columns when it is too large.
%\begin{lstlisting}
%A code listing is needed here.
%\end{lstlisting}
\end{@twocolumnfalse}
]
This part of the document doesn't span the two columns when it is too large.
\end{document}
Just to let people looking for the error find this page I'll cite the appearing error:
Argument of \lst@next has an extra }.
<inserted text>
\par
l.13 ]
Additional Questions (if allowed):
The main idea is to meet the initial request, however, if your kindness go beyond sight, you may want to answer to me:
- Why the conflict happens?
- How should one solve it?

lstlistingenvironment) places the full-width material at the top of a new page. Have you considered using atable*(orfigure*) environment, without a\captiondiective, to typeset the material? It works just fine with thelstlistingmaterial, by the way. And, as a bonus, you automatically get some whitespace inserted between the full-width and two-column material. – Mico Nov 26 '17 at 08:42