We investigate the formation of carbon stars as a function of the stellar mass and parent metallicity. Theoretical modelling is based on an improved scheme for treating the third dredge-up in synthetic calculations of thermally pulsing asymptotic giant branch (TP-AGB) stars. In this approach, the usual criterion (based on a constant minimum core mass for the occurrence of dredge-up, M
cmin) is replaced by one on the minimum temperature at the base of the convective envelope, T
bdred, at the stage of the post-flash luminosity maximum. Envelope integrations then allow determination of M
cmin as a function of stellar mass, metallicity, and pulse strength (see Wood 1981), thus inferring if and when dredge-up first occurs. Moreover, the final possible shut down of the process is predicted. Extensive grids of TP-AGB models were computed by Marigo (1998, Ph. D. Thesis, University of Padova and
1998A&A...340..463M) using this scheme. In this paper, we present and discuss the calibration of the two dredge-up parameters (i.e. efficiency λ and T
bdred) aimed at reproducing the carbon star luminosity function (CSLF) in the LMC, using TP-AGB models with original metallicity Z=0.008. In addition to this, the effects of different input quantities on the theoretical CSLF are analyzed. It turns out that the faint tail is almost insensitive to the history of star formation rate (SFR) in the parent galaxy, in contrast to the bright wing which may be more affected by the details of the recent history. Actually, we find that the faint end of the CSLF is essentially determined by the temperature parameter T
bdred. Once the faint end is reproduced, the peak location is a stringent calibrator of the efficiency parameter λ. The best fit to the observed CSLF in the LMC is obtained with λ=0.50, logT
bdred=6.4, and a constant SFR up to an age of about 5x10
8yr. This recent drop of the SFR is invoked to remove a slight excess of bright carbon stars otherwise predicted. A good fit to the observed CSLF in the SMC is then easily derived from the Z=0.004 models, with a single choice of parameters λ=0.65, logT
bdred=6.4, and a constant SFR over the entire significant age interval. The result for λ is consistent with the theoretical expectation that the third dredge-up is more efficient at lower metallicities.